Why isn't List.toArray() generic? Why must you give the type as an argument (and usually create a new empty instance)?
public Object[] toArray()
http://docs.oracle.com/javase/7/docs/api/java/util/List.html#toArray()
Update: I have since learned that generic array creation is not allowed, but I believe that it should be. Is there any reason why it's not allowed?
Main.java:28: error: generic array creation
T[] ret = new T[size()];
Update: Ok I believe this is the answer:
http://docs.oracle.com/javase/tutorial/java/generics/restrictions.html#createArrays
Not because it is directly relevant, but indirectly relevant. There is nothing inherently wrong with new T[size()], where MyList<String> would be turned into new String[size()], but T could itself be a parameterized type. So if you were to create MyList<Set<Integer>>, then T would equal Set<Integer> and the compiler would try to create new Set<Integer>[size()], which could lead to the problem in the link when returned. Someone tried to give an answer along these lines but that answer has since been deleted so I forgot who it was.
toArraythat is generic