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 - h5微信中怎么禁止横屏2. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””3. python - 怎么查看网址做的是什么反爬虫4. node.js - webpack required打包问题5. Docker for Mac 创建的dnsmasq容器连不上/不工作的问题6. boot2docker无法启动7. docker-compose中volumes的问题8. 为什么我ping不通我的docker容器呢???9. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?10. nignx - docker内nginx 80端口被占用

网公网安备