使用TreeMap的key必须实现Comparable接口

解决方案 »

  1.   

    class YourClass implements Comparable{
       ....
       // return positive(+) , 0 , negative(-) for
       // this is greater(>) than, equal to(=) or less than(<) the object to compare with
       //e.g.:
       
       public int compareTo(Object o){
          hashCode() - ((YourClass)o).hashCode();
       }
    }
      

  2.   

    你的类必须实现Comparable接口,并且覆写compareTo方法