黑马程序员技术交流社区
标题:
求解泛型问题 帮我编译查看下哪里的错误
[打印本页]
作者:
宋旭东
时间:
2013-7-3 19:15
标题:
求解泛型问题 帮我编译查看下哪里的错误
import java.util.*;
class Person
{
private String name;
Person(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public String toString()
{
return "person:"+name;
}
}
class Student extends Person
{
Student(String name)
{
super(name);
}
}
class Worker extends Person
{
Worker(String name)
{
super(name);
}
}
class GenericDemo3
{
public static void main(String[] args)
{
//Student s = new Student();
TreeSet<Student> ts = new TreeSet<Student>();
ts.add(new Student("lisi01"));
ts.add(new Student("lisi02"));
ts.add(new Student("lisi03"));
Iterator<Student> it = ts.iterator();
while (it.hasNext())
{
System.out.println(it.next().getName());
}
/*Student s = new Student("lisi001");
System.out.println(s.getName());*/
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2