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 - .vue页面跳转问题2. java - 微信小程序中 无缘无故的提示(图片的加载失败)3. [python2]local variable referenced before assignment问题4. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)5. javascript - 像这种内联Js绑定方式,如何定位到js代码?6. python - 一个程序中的切片问题7. javascript - 使用form进行页面跳转,但是很慢,如何加一个Loading?8. javascript - vue-cli中 用proxyTable实现了跨域,用get访问没有问题,但通过 post传数据就出现了问题9. css - 手机app中rem的基准值计算错误10. module - python模块from import语句相对导入,加不加点号有什么区别?

网公网安备