Arrays class contain a function to convert arrays into list.When i convert the array of Integer into ArrayList it will throw an exception.
Integer[] array = new Integer[]{2, 4, 3 , 9};
ArrayList<Integer> test = (ArrayList<Integer>) Arrays.asList(array);
The Arrays.asList(array) return a List of type Integer, when i convert the list of Integer to ArrayList, it will throw an exception
java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
ArrayList implements the List interface, so why this throw an exception ?
When i try catch the object direct with List reference variable, this work fine.