Additionally, since you are using raw types with your arraylist, the compiler couldn't catch that mistake for you either.... and .... of course, arrays don't implement Comparable, hence, the class cast exception.
Lilou Laure wrote:
I didn't get this part . I'm using raw types, fine, but the asList(T... a) takes T... a as argument, and when a primitive type array is being passed, why doesn't the compiler detect a type mismatch between the generic class type T and the primitive int ?
Lilou Laure wrote:If I'm not using raw types, what would be the change ? can you give me an example please ?
Lilou Laure wrote:and why doesn't it get autoboxed as in this : Object ob=9;
Lilou Laure wrote:Ok.
When the asList() returns a List reference what is the object/ instance exactly whose reference is being returned.
and how does the asList() actually work , in terms of changing the backed the array ?
Roel De Nijs wrote:The implementation of the asList() method is quite simple
Lilou Laure wrote:Roel, in your implementation of asList(), you have given that it just returns an arraylist initialized with a copy of the array passed in.
Lilou Laure wrote:But how are changes made in the arraylist reflected in the original array and vice versa ?
How does that part work actually ? For example if we call methods like, set() , size(), what exactly happens,?