import java.util.*; class ClassA implements Comparable { private int value; ClassA(int value){ this.value = value; } public int compareTo(ClassA ca){ return value - ca.value; } @Override public int hashCode(){ return value; } @Override public boolean equals(Object o){ return value == ((ClassA)o).value; } public int getValue(){ return value; } } class Reverse { static Comparator> reverseOrder(){ return new Comparator(){ public int compare(T o1, T o2){ return o2.compareTo(o1); } }; } } class Samp19 { public static void main(String[] args){ Comparator ca = Reverse.reverseOrder(); System.out.println(ca.getClass().getName()); TreeSet tsa = new TreeSet(ca); tsa.add(new ClassA(30)); tsa.add(new ClassA(20)); tsa.add(new ClassA(10)); for(ClassA c: tsa){ System.out.println(c.getValue()); } } }