This content has been marked as final. Show 3 replies
Dennis_Martinez wrote:I suspect you know how to use lists and ask for an example demonstrating the inherent unsafety. So here it is:
Could I see an example? I'm a little lost on doing so.
Compare this to:
List<String> generic = new List<String>; // assume this works List<Integer> ints = new ArrayList<Integer>(); ints.add(42); Object o = generic; o = ints; // this should not work, but it does (erasure) List<String> strings = generic; // really it's a list of Integers, ohoh // now you pass that list somewhere completely unrelated and try to get an element: String s = strings.get(0); // ClassCastException
With kind regards
String strings = new String; Object objects = strings; objects = 42; // ArrayStoreException