Last week I wrote about value types, which are one of the new language features that are being investigated for a future version of Java. Next one is “Generic Specialization”.
Under Generic Specialization , you can have a
List<int>. The purpose of generic specialization is to make it possible to use
primitive types. Below is the example.
At first sight you might think: that’s simple, it’s just an extension of auto-boxing, just make
List<int> an alias for
List<Integer> , but that would not be very satisfactory.
List<Integer> is a subtype of
List<?>, which is a subtype of the
raw type List. Because of that we can write code like this:
But the same relations will not be true for a
ArrayList<int> is not a
List<?> nor a raw List because
List<T> always expect T as an object