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. web - Flash 和 HTML 交互的方式有哪几种?如何选择?2. css3 - 关于nth:child(2)的问题3. node.js - nodejs 的sails 框架如何修改ejs的后缀为html4. CSS3动画导致图片模糊5. css - BFC外边距折叠问题6. android - 哪位大神知道java后台的api接口的对象传到前端后输入日期报错,是什么情况?求大神指点7. mac里的docker如何命令行开启呢?8. 求救一下,用新版的phpstudy,数据库过段时间会消失是什么情况?9. vue添加锚点,实现滚动页面时锚点添加相应的class操作10. mysql updtae追加数据sql语句
