DESKTOP-72IFJTH_20200907-赵亚军

1、问题:这两比较器为啥不一样

public void sort() {
        Comparator<String> comparator = new Comparator<String>() {
            @Override
            public int compare( String first , String second ) {
                return first.compareToIgnoreCase( second );
            }
        };
        Arrays.sort( words , comparator );
    }***类名:WordSorter
public void sort() {
        Comparator<String> comparator = new Comparator<String>() {
        Arrays.sort( words , comparator );
    }
    Comparator<Tiger> comparator = new TigerComparator() ;//父类引用变量指向子类对象
        
        Arrays.sort( tigers , comparator );
        
        System.out.println( Arrays.toString( tigers ) );

    }
        

2、第一个比较器里比较的都是string类型,而第二个比较器里比较左边比较Tiger型,右边默认比较的是object型,此处的TigerComparator是子类

标签

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1