John de Michele wrote:Kevin:
Because generics in Java don't work that way. You can't assign an array of EnumMap<T, U> to an array of Map<T, U>.
Actually you can, once you are able to create one. Because Map is a super type of EnumMap, Map[] is a super type of EnumMap[].
Creating the array is the problem, because generics don't allow you to create arrays of generic types. The reason is because the compiler cannot guarantee type safety anymore. Consider, assuming line 1 would not create a compiler error:
With non-generic types line 3 would have already created a ClassCastException, and therefore it's easier to find the cause of the problem. In this case the ClassCastException comes at a point where you no longer know why it went wrong.
Anyway, with only one compiler warning you can create the
values map: