posted 13 years ago
a)
inconvertible types
found : java.util.ArrayList<A>
required: java.util.ArrayList<B>
ArrayList<B> three=(ArrayList<B>)one;
i know why the above compile time error come as this is not allowed in generics
b)
here we are casting from two ArrayList that can accept anything to ArrayList that accept objects of type B
shouldn't there be compile-time error.i mean object and ArrayList<B>
while in this case,classcastexception occurs
Exception:
java.lang.ClassCastException: A cannot be cast to B
why such difference in case of collection and normal classes???
OCPJP 6.0 93%
OCPJWCD 5.0 98%