I was just looking at the method defined in the List interface:
, and I have a question. Why is it generic? Because of that fact, m
It is declared generically so that you can write code such as
Integer[] intArray = list.toArray(new Integer[0]);
without casting the array coming back.
It is declared with the following annotation:
@SuppressWarnings("unchecked")
In other words, Java is trusting you to pass in an array parameter of the same type, so your error does not occur.