This means that the class agrees to respond to methods defined by the " interface " Comparable .
The advantage that you have with this (and any other declaration "implements") is that you can " abstract " the type of object and code for the interface.
Consider this
class A implements Comparable { .... } class B implements Comparable { .... } class C implements Comparable { .... }
Then you can encode something that you can use Comparable instead of a specific type:
public void doSomethingWith( Comparable c ) { c.compareTo( other );
And call it like this:
doSomethingWith( new A() ); doSomethingWith( new B() ); doSomethingWith( new C() );
Since you don't care what type of class you just need it to implement the interface.
This (a program for an interface, not an implementation) is one of the most powerful methods in the OO programming world, as it promotes low-connect .
source share