I have an ArrayList of Objects(POJOs) that have an Id and another field. I have implemented the equals()/hashcode() override in the POJO for the Id field. When I compare two objects using the equals() method of the Object class, it works perfectly fine. However when I add these objects to an arraylist and implement the
Collections.sort(arrListOfObjects);
it gives me a classCastexception. I looked up and found that I need to implement a Comparator. This comparator also does something to equals/hashcode override. If that is so then why does the above code not work?(I know that there is no comparator, but my question is, is it not possible to implement a sort based on the hashcode of the object?)