capint
1/31/2017 - 5:44 PM

Java >> Generics >> Wildcard

Java >> Generics >> Wildcard

Integer is a subtype of Number but Box<Integer> is NOT a subtype of Box<Number>. Both Box<Integer> and Box<Number> are subtypes of Object

ArrayList<String> is a subtype of List<String> is a subtype of Collection<String> => So long as you do not vary the type argument, the subtyping relationship is preserved between the types

Since Integer is a subtype of Number => List<Integer> is a subtype of List<? extends Number> and List<? extends Integer> is a subtype of List<? extends Number>

"?" represents "? extends Object" => List<A> is a subtype of List<?>