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,293
  • 17
  • 62
  • 84

2 Answers2

11

This is not possible in Java.

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

Björn Pollex
  • 72,744
  • 28
  • 189
  • 274
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.