import java.util.*;
class Generic6
{
public static void sop(Object obj)
{
System.out.println(obj);
}
public static void main(String[] args)
{
TreeSet<Student> a1 = new TreeSet<Student>(new Comp());
a1.add(new Student("abc2"));
a1.add(new Student("abc3"));
a1.add(new Student("adc8"));
a1.add(new Student("abc5"));
printoo(a1);
/*TreeSet<Integer> a2 = new TreeSet<Integer>();
a2.add(1);
a2.add(6);
a2.add(8);
a2.add(3);*/
//printoo(a2);
System.out.println("Hello World!");
}
public static void printoo(TreeSet< Student> a)
{
Iterator<Student> it = a.iterator();
while(it.hasNext())
{
sop(it.next());
}
}
}
class Comp implements Comparator<Persion>//为什么String不能编译通过?
{
public int compare(Persion s1, Persion s2)
{
return s1.getName().compareTo(s2.getName());
}
}
class Persion
{
private String name;
//private int age ;
Persion(String name){//, int age
this.name = name;
//this.age = age;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public String toString(){
return "name"+name;
}
}
class Student extends Persion
{
Student (String name){
super(name);
}
}
class Worker extends Persion
{
Worker (String name){
Super(name);
}
}
提示是这句有错但没发现错哪儿了。。还能运行,但结果不正确。。
|