51全棧網(wǎng)絡(luò)安全高級工程師精品班
2022-10-24 00:05 作者:janet19961217 | 我要投稿
public class GenericsBind {
? ?public static <T> void sort(List<T> list, Comparator<? super T> c) {
? ? ? ?list.sort(c);
? ?}
? ?// T => Cat
? ?public static void main(String[] args) {
? ? ? ?sort(new ArrayList<Cat>(), new CatComparator());
? ? ? ?sort(new ArrayList<Cat>(), new AnimalComparator());
? ?}}
標(biāo)簽: