7

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 to ArrayList<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?

user7294900
  • 47,183
  • 17
  • 74
  • 157

1 Answers1

1

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).

newacct
  • 110,405
  • 27
  • 152
  • 217