Menu

#174 [] list syntax can give ClassCastExceptions

open
nobody
None
5
2006-06-21
2006-06-21
B S
No

This line of code compiles and gives a
ClassCastException at runtime.

LinkedList<String> list = [ "1","2"];

Exception in thread "main"
java.lang.ClassCastException: nice.lang.rawObjectArray

It should either turn the rawObjectArray into a
LinkedList via new LinkedList(Collection), make it as a
LinkedList to begin with, or give a compile time error.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB