Does anybody know why Java 1.6 has this behaviour:
List<String> list = ArrayList<String>();
String[] arr = (String[]) list.toArray();
And I get a ClassCastException, because it returns Object[] and not String[].
I thought
List<T>.toArray()
should return T[] - no? Does anyone have an answer why this inconvenience exists in the language?
And also how to work around this? How do I get a String[] from List<String>
without looping thru the items?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…