Constraints while designing the Java generics
- by Andrea
Java generics look quite different from those available in Scala, although both were designed by Martin Odersky. From my point of view, the design of generics in Java is worse, for instance:
there is no possibility to specify variance
one can get around the previous limitation by using wildcards, but this means the burden of specifying variance goes on the caller instead of the library designer
one cannot use a type constructor in generics
What were the constraints in Java that forced Odersky to design this mechanism for generics instead of the more flexible one he devised for Scala? Was he just savvier a few years later or there were actual limitations due to Java?