Reputation: 58812
You cannot create arrays of parameterized types, so this code in Eclipse
ArrayList<Integer>[] list = new ArrayList[1];
Can't be parameterized , but Eclipse shows a warning
Type safety: The expression of type
ArrayList[]
needs unchecked conversion to conform toArrayList<Integer>[]
And also shows suggestion Infer Generic Type Arguments which does nothing when submitted.
Infer Generic Type Arguments Replaces raw type occurrences of generic types by parameterized types after identifying all places where this replacement is possible.
Should this suggestion be removed or am I missing something?
Upvotes: 8
Views: 176
Reputation: 122489
Yes, the suggestion should be removed. It is not possible to replace the raw type with a parameterized type here, because an array creation expression must use a reifiable type as the component type. It's illegal to do new ArrayList<Integer>[1]
. You can only do new ArrayList[1]
or new ArrayList<?>[1]
, both of which will produce a warning in order to convert to type ArrayList<Integer>[]
(the second one will require an explicit cast which produces an unchecked cast warning).
Upvotes: 1