Today I was asked this interview question:
If I have a
Person
class withname
,age
andsalary
fields, and I put 100 new instances of thisPerson
in anArrayList
, and then doCollections.sort(list)
, then on what parameter will the list be sorted?
I understand that I need to have the Person
class implement Comparable
and then override compareTo
, but if I don't do that, what will happen?