Generics Flashcards

1
Q

Generics in general

A

Generics give you great Compile time Type Safety and the code Reusability

Something about generics in collections .
Collections are invariant .. is List<String> is not a subtype of List<object></object></String>

Wildcards allow a bit of flexibility to that

List<String> is a subtype of List<T>
List<object> is a subtype of List<T></T></object></T></String>

Producer Extends Consumer Super

? extends Object : can be any class that is T or extends T ( T is Object here)
? super String : can be any class that is a super class/interface of String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly