Java Generics

less than 1 minute read

I think the The Craftsman 44: Java Generics 2 gives the best exaplaination on when to use extends or super when defining Generics.

Basically use

you can widen the type of a list by using ? extends X, only if you
plan on reading from that list

and

If you plan on writing to that list, use <? super X>

Categories:

Updated:

Leave a Comment