class 节目 implements Comparable<Object>,Serializable
{ String name;double time;  节目(String name,double time)
   { this.name=name;
      this.time=time
   }
  public int compareTo(Object b)
  { 节目 item=(节目)b;
    return(int)((this.time-item.time)*1000);
   }
}
public class A 
{  public static void main(String[] args)
    { TreeSet treeset=new TreeSet( new Comparator<Object>() 
                                { public int compare(Object a,Object b)
                                   { 节目 item_1=(节目)a;
                                     节目 item_2=(节目)b;
                                   return item_1.compareTo(item_2);
                                }
                                });   节目 programe=new ("电影",7.0);
  节目 programe1=new ("歌剧",17.0);
  节目 programe2=new ("诗歌",21.0;
  treeset.add(programe);
  treeset.add( programe1);
  treeset.add(programe2);
  }}这儿是往树集中添加对象,对象是按其属性时间来排列,这儿实现了Comparable接口的类实现序列化有什么作用???

解决方案 »

  1.   

    实现java.lang.Serializible就可以了,无需管其他,Comparable用来作排序,sort方法时用
      

  2.   

    我看到中文类名振了
    Serializible 一般是用来网络传输用,Comparable用来排序
      

  3.   

    我知道实现Comparable接口的作用,这儿实现序列化接口又有什么作用,这儿不用序列化接口也没问题,为什么还是采用了序列化??
      

  4.   

    你这可以不用啊。
    有时候是为了消除warning.
      

  5.   

    实现java.lang.Serializible就可以了,无需管其他,Comparable用来作排序,sort方法时用