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


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



Leave a Comment