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
If all your classes implement a Living interface defined as it follows (always a good idea in Java):
public interface Living {
int getLifeTime();
}
you can sort your collections of Living objects by using the lambdaj library as it follows:
List sortedLivings = sort(livings, on(Alive.class).getLifeTime());