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. angular.js - angularjs的自定义过滤器如何给文字加颜色?2. docker不显示端口映射呢?3. angular.js使用$resource服务把数据存入mongodb的问题。4. docker镜像push报错5. 为什么我ping不通我的docker容器呢???6. dockerfile - 为什么docker容器启动不了?7. docker 17.03 怎么配置 registry mirror ?8. docker api 开发的端口怎么获取?9. html5 - 如何让H5页面在手机浏览器里和微信全屏显示10. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?

网公网安备