我定义了一个比较器
public class CompareByName implements Comparator<Person> {......}
这个比较器是不是只能比较 Person 类型的对象?
Set<Student> has2 = new TreeSet<Student>(new CompareByName() );
然而为什么用Person的子类Student也能使用比较器呢?
public class CompareByName implements Comparator<Person> {......}
这个比较器是不是只能比较 Person 类型的对象?
Set<Student> has2 = new TreeSet<Student>(new CompareByName() );
然而为什么用Person的子类Student也能使用比较器呢?