- <DIV class=blockcode>
- <BLOCKQUOTE>import java.util.*;
- class TreeSetDemo4
- {
- public static void main(String[] args)
- {
- TreeSet ts =new TreeSet();
- ts.add(new Student("lisi02",22));
- //ts.add(new Student("lisi02",15));
- //ts.add(new Student("lisi007",28));
- //ts.add(new Student("lisin05",19));
- //ts.add(new Student("lisin08",19));
- //ts.add(new Student("lisin08",16));
- //ts.add(new Student("lisia08",19));
- Iterator it= ts.iterator();
- while(it.hasNext())
- {
- System.out.println(it.next());
- }
- }
- }
- class Student
- {
- private String name;
- private int age;
- Student(String name,int age)
- {
- this.age=age;
- this.name=name;
- }
- public String getname()
- {
- return name;
- }
- public int getage()
- {
- return age;
- }
- }
复制代码
虽然没有实现Compareable接口但是为什么只添加一个实例对象就会报错呢。
|
|