compare and sort different type of objects using java Collections
问题 How to compare and sort different type of objects using java Collections .Below is the use case: For example DOG,MAN,TREE, COMPUTER,MACHINE - all these different objects has a common property say "int lifeTime". Now I want to order these obects based on the lifeTime property Thx 回答1: All of these objects should have a common abstract class/interface such as Alive with a method getLifeTime() , and you could have either Alive extends Comparable<Alive> or create your own Comparator<Alive> .