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. docker绑定了nginx端口 外部访问不到2. python - 使用pandas的resample报错3. docker内创建jenkins访问另一个容器下的服务器问题4. javascript - 使用vue做个抽奖问题5. gulp-ruby-sass编译出来的文件有错6. java - xml 传输数据如何处理更好7. javascript - 关于vue-cli每次都要build才能放到线上问题。8. node.js - windows下安装webpack时出现路径问题如何解决?9. android - 类似于微信朋友圈图片这样的是在listview中嵌套gridview还是动态加入多个imageview呢?10. java - SSH框架中写分页时service层中不能注入分页类

网公网安备