0

What is the difference between m: util.AbstractMap[_, _] and m: util.AbstractMap?

PS. The question I think holds for any collection, not just this one.

Daniel
  • 5,839
  • 9
  • 46
  • 85
  • Just to give you something to google: the first one is an *existential type* and the second one is a *higher-kinded type* or *type constructor*. – ghik Jan 20 '16 at 09:49

1 Answers1

1

In scala you have to necessarily provide the type argument. So in literal sense, you cannot do new util.AbstractMap.

Well if you think of it, its correct. In Java, one can avoid giving the parametric type and the code compiles, so as to be backward compatible with pre-java5 code. But in scala, generics have been a part from the start.

If the question was for instead something like this:

trait MonoidK[F[_]]{...}
MonoidK[List].combine[Int](List(1,2,3),List(4))

Where we do not provide the argument types for List, then List in this case is a Type Constructor to which arguments have to be provided later (in combine method). MonoidK in this case is supporsedly called higher kinded type. This is a good read on this topic for more details.

Community
  • 1
  • 1
Jatin
  • 31,116
  • 15
  • 98
  • 163