Sending new Object[4] to String[] does not work because Object[] not String[] , just as Object not String .
The first example works because of the type of erasure . At run time, a parameter of type Item was deleted to Object . However, this will also work if you tried to assign an array to the return type, for example, if data not private :
String[] strings = new GenericStack<String>(42).data;
This would also throw a ClassCastException , because in fact Object[] would be discarded on String[] .
source share