4

In Java, what interface(class) should a class implement(extend) in order to allow two instances of the class to be comparable through relational operators like "<" or ">="?

Tiago Veloso
  • 8,513
  • 17
  • 64
  • 85

2 Answers2

11

This is not possible in Java.

If you want objects of your class to be comparable, implement Comparable.

Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
4

Java does not support operator overloading, so you're out of luck. Implementing java.lang.Comparable or providing a java.util.Comparator is what you're supposed to do.