I was reading Effective Java by Josh Bloch and I came across an Item 24: Eliminate unchecked warnings.
In that they give an example of toArray() method of the class which generates unchecked warning.
ArrayList.java:305: warning: [unchecked] unchecked cast
found : Object[], required: T[]
return (T[]) Arrays.copyOf(elements, size, a.getClass());
I am not bale to understand how the compiler is diagnosing that it would return Object[]?
May be I am not able to understand the type erasure phenomena behind it.
Can somebody explain me how Object[] would be returned?
Thanks in advance.