TreeMap Test
import java.util.Map;
import java.util.TreeMap;
class Test{
int a;
Test(int a){
this.a = a;
}
}
public class TreeMapTest {
public static void main(String[] args){
Test t1 = new Test(1);
Test t2 = new Test(1);
Map<Test,Integer> map = new TreeMap<>();
map.put(t1, 1);
map.put(t2, 1);
System.out.println(map.size());
}
}
OUTPUT
Exception in thread "main" java.lang.ClassCastException: Test cannot be cast to java.lang.Comparable