能解决
1.集合中防止数据转换异常
2.参数通用化 -“模板”html
优势java
泛型主要在集合类中使用,eg:
List<String> list = new ArrayList<String>();
String s = list.get(0); //取出来的数据直接就是泛型规定的类型,不用作类型转化,从而避免类型转化异常segmentfault
自定义泛型
泛型类 只能用在成员变量上,只能使用引用类型
泛型接口 只能用在抽象方法上
泛型方法 返回值前面加上<T>ide
?是通配符,泛指全部类型,常定义一个引用变量
? extends T 指T类型或T的子类型
? super T 指T类型或T的父类型
参考:http://www.javashuo.com/article/p-usdtcgkv-ek.htmlhtm
Android经常使用场景是适配器和数据解析(Retrofit+Rxjava)
参考:
http://www.javashuo.com/article/p-tdlvtkjj-bd.html
http://www.javashuo.com/article/p-mtrmmvbn-gv.html
https://www.jianshu.com/p/b25966f1d699blog