本帖最后由 丁岩 于 2012-8-25 09:05 编辑
- import java.util.*;
- class People
- {
- private String name;
- People(String name)
- {
- this.name=name;
- }
- public String getName()
- {
- return name;
- }
- }
- class Workers extends People
- {
- private int age;
- Workers(String name,int age)
- {
- super(name);
- this.age=age;
- }
- public int getAge()
- {
- return age;
- }
- }
- public class Gener7
- {
- public static void main(String[]args)
- {
- TreeSet<People> tr=new TreeSet<People>();
- tr.add(new People("e"));
- tr.add(new People("de"));
- tr.add(new People("cde"));
- tr.add(new People("bcde"));
- TreeSet<Workers> wk=new TreeSet<Workers>();
- wk.add(new Workers("ab",10));
- wk.add(new Workers("bc",8));
- wk.add(new Workers("cd",6));
- wk.add(new Workers("ef",4));
- prints(wk);
- /* Iterator<People> it1=tr.iterator();
- while(it1.hasNext())
- {
- System.out.println(it1.next().getName());
- }
- */
- }
- public static void prints(Collection<? extends People> al)
- {
- Iterator<? extends People> it=al.iterator();
- while(it.hasNext())
- {
- System.out.print(it.next().getName());
- }
- }
- }
复制代码 不知道错在哪了
|