public class EmpComparator implements Comparator {
public int compare(Object obj1, Object obj2) {
Person emp1 = (Person) obj1;
Person emp2 = (Person) obj2;
int nameComp = emp1.getFirstName().compareTo(emp2.getFirstName());
return ((nameComp == 0) ? emp1.getLastName().compareTo(
emp2.getLastName()) : nameComp);
}
I am feeling really sick right now because of 2 things in this example which I'm obviously missing
1. Why doesn't he just return the "nameComp" variable..
2. In the "true" part of the ternary value he does "emp1.getLastName().compareTo(emp2.getLastName())" why.. the value is already in nameComp.
Please explain
Thanks!