java - 一个泛型标签问题
问题描述
新手问一个泛型问题
public static void main(String[] args) {ArrayList<Student> al = new ArrayList<>();al.add(new Student('大石榴',17,100));al.add(new Student('地雷',20,80));al.add(new Student('张大炮',21,60));Comparator<Student> cp = new Comparator<Student>() {@Override public int compare(Student o1, Student o2) {return o1.getAge() - o2.getAge(); }}; Collections.max(al, cp);//public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)//这是max方法的源码.// <T> 这个泛型在哪获取到的?for(Student st : al){ System.out.println(st);} }
问题解答
回答1:Java中的泛型都是使用了类型擦除,你这里的<T> 只是一个类型变量。这个方法里面也只是用来代表@param <T> the class of the objects in the collection
相关文章:
1. javascript - 求解答:实例对象调用constructor,此时constructor内的this的指向?2. python中生产者消费者线程问题3. Windows系统能否利用Docker使用Ubuntu吗?Ubuntu能使用本机的显卡吗?4. 请教,关于python字典,合并相同值的键的实现方法5. python的MySQLdb库中的executemany方法如何改变默认加上的单引号?6. android - 京东移动端网页和其app加载的url所做的呈现不应该是完全一样的吗?7. mysql5.7就没有官方性质的详细配置文件吗?求大神告知8. 百度地图api - Android 百度地图 集成了定位,导航 相互的jar包有冲突?9. css3中translate(-50%,-50%)对 transform-origin的奇葩影响?10. html5 - 在一个页面中 初始了两个swiper 不知道哪里错了 一直不对

网公网安备