本帖最后由 王超 于 2012-6-14 16:02 编辑
- import java.util.*;
- class GenericDemo7
- {
- public static void main(String[] args)
- {
- TreeSet<Student> ts = new TreeSet<Student>(new Comp());
- ts.add(new Student("ssss7"));
- ts.add(new Student("ssss4"));
- ts.add(new Student("ssss8"));
- ts.add(new Student("ssss1"));
- Iterator<Student> it = new ts.iterator();
- while(it.hasNext())
- {
- System.out.println(it.next().getName());
- }
- }
- }
- class Comp implements Comparator<Person>
- {
- public int compare(Person p1,Person p2)
- {
- return p1.getName().compareTo(p2.getName());
- }
- }
- class Person
- {
- private String name;
- Person(String name)
- {
- this.name = name;
- }
- public String getName()
- {
- return name;
- }
- }
- class Student extends Person
- {
- Student(String name)
- {
- super(name);
- }
- }
复制代码 错误提示:GenericDemo7.java:12: 软件包 ts 不存在
Iterator<Student> it = new ts.iterator(); |
|