Compare two objects with “<” or “>” operators in Java
问题 How to make two objects in Java comparable using "<" or ">" e.g. MyObject<String> obj1= new MyObject<String>(“blablabla”, 25); MyObject<String> obj2= new MyObject<String>(“nannaanana”, 17); if (obj1 > obj2) do something. I've made MyObject class header as public class MyObject<T extends Comparable<T>> implements Comparable<MyObject<T>> and created method Comp but all the gain I got is now I can use "sort" on the list of objects, but how can I compare two objects to each other directly? Is if