  The hull of a linear code is the intersection of itself with its dual code
with respect to certain inner product. Both Euclidean and Hermitian hulls are
of theorical and practical significance. In this paper, we construct several
new classes of MDS codes via (extended) generalized Reed-Solomon (GRS) codes
and determine their Euclidean or Hermitian hulls. Specifically, four new
classes of MDS codes with Hermitian hulls of flexible dimensions and six new
classes of MDS codes with Euclidean hulls of flexible dimensions are
constructed. For the former, we further construct four new classes of
entanglement-assisted quantum error-correcting codes (EAQECCs) and four new
classes of MDS EAQECCs of length $n>q+1$. For the latter, we also give some
examples on Euclidean self-orthogonal and one-dimensional Euclidean hull MDS
codes.
