Why is Java Comparable used? Why would someone implement Comparable in a class? What is a real life example where you need to implement comparable
OK, but why not just define a compareTo() method without implementing comparable interface.
For example a class City defined by its name and temperature and
public int compareTo(City theOther)
{
if (this.temperature < theOther.temperature)
return -1;
else if (this.temperature > theOther.temperature)
return 1;
else
return 0;
}