The first allows process
of a List<Integer>
, a List<Double>
, etc. The second doesn't.
Generics in Java are invariant. They're not covariant like arrays.
That is, in Java, Double[]
is a subtype of Number[]
, but a List<Double>
is NOT a subtype of List<Number>
. A List<Double>
, however, is a List<? extends Number>
.
There are good reasons for generics being invariant, but that's also why the extends
and super
type are often necessary for subtyping flexibility.
See also
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…