在Java中,类应该实现(扩展)什么接口(类),以便允许类的两个实例通过诸如“<”或“> =”之类的关系运算符进行比较?
This is not possible in Java.
If you want objects of your class to be comparable, implement Comparable
.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.