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接口的类实现序列化有什么作用???
{ 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接口的类实现序列化有什么作用???
Serializible 一般是用来网络传输用,Comparable用来排序
有时候是为了消除warning.