java泛型方法
public static <K extends Comparable<? super K>, V> Comparator<Map.Entry<K,V>> comparingByKey() {
return (Comparator<Map.Entry<K, V>> & Serializable)
(c1, c2) -> c1.getKey().compareTo(c2.getKey());
}
<K extends Comparable<? super K>, V> :类型参数声明
K extends Comparable<? super K>, V :类型参数 (泛型类型名称的标识符)
类型参数
1.Comparator<Map.Entry<K,V>> 声明返回值类型
2.实际参数类型的占位符
3.代表引用型类型
4.不能是原始类型(像int,double,char的等)
有界的类型参数: <K extends Comparable<? super K>, V>
1.extends
2.implements
3.super
4.上界:Comparable<? super K>
java泛型类 (参数化的类或参数化的类型)
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable
{ }
<K,V>:类型参数声明部分
类型通配符:?
1.List<?> 所有List<具体类型实参>的父类
2.通配符上线 List
3.List<? extends Number> 下层子类类型 Number
4.List<? super Number> 下层子类类型 Number 的父类
E - Element 集合中使用
T - Type(Java 类),指定类型
K - Key(键)
V - Value(值)
N - Number(数值类型)
? - 类型通配符