Code:
public class CompareTest {
public static void main(String[] args) {
ArrayList list = new ArrayList();
(list).add(new CompareTest());
Arrays.sort(list.toArray()); //Does not throw Exception , why ?
Collections.sort(list); //throws ClassCastException
}
}
As per Java Doc: Arrays#sort
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements. All elements in the array must implement the Comparable interface.
Why does Arrays#sort , doesnt throw ClassCastException
as stated by JavaDoc ?