I want to know why the .compareTo()
is in the Comparable
interface while a method like .equals
is in the Object
class. To me, it seems arbitrary why a method like .compareTo()
is not in the Object
class already.
To use .compareTo()
, you implement the Comparable
interface and implement the .compareTo()
method for your purposes. For the .equals()
method, you simply override the method in your class, since all classes inherit from the Object
class.
My question is why is a method like .compareTo()
in an interface that you implement rather than in a class like Object
? Likewise, why is the .equals()
method in the class Object
and not in some interface to be implemented?
Eq
typeclass).