- import java.util.*;
- public class fanxing {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- ArrayList<Person> a1 = new ArrayList<Person>();
- a1.add(new Person("abc1"));
- a1.add(new Person("abc2"));
- a1.add(new Person("abc3"));
-
- ArrayList<Student> al1 = new ArrayList<Student>();
- al1.add(new Student("abc--1"));
- al1.add(new Student("abc--2"));
- al1.add(new Student("abc--3"));
- printColl(al1);
- }
- public static void printColl(ArrayList<? extends Person> a1){
- Iterator<? extends Person> it = a1.iterator();
- while(it.hasNext()){
- System.out.println(it.next().getName());
- }
- }
- }
- class Person{
- private String name;
- Person(String name){
- this.name = name;
- }
- public String getName(){
- return name;
- }
- }
- class Student extends Person implements Comparable<Person>{
- Student(String name){
- super(name);
- }
- public int compareTo(Person s){
- this.getName();
-
- }
- }
- class Comp implements Comparator<Person>{
- public int compare(Student s1,Student s2){
- return s1.getName().compareTo(s2.getName());
- }
- }
复制代码 |
|