Java Book: Generics and Collections

Java Generics and Collections by Maurice Naftalin and Philip Wadler seems to be a very fine introduction to Java generics with emphasis on the Collection classes.

One of the things I never really got about generics is the correct use of super wildcards. While I found extends wildcards to be rather easy to grasp, super wildcards always managed to confuse me. In chapter 2, I found the first definition I immediately understood:

The Get and Put Principle. Use an extends wildcard when you only get values out of a structure, use a super wildcard when you only put values into a structure, and don’t use a wildcard when you both get and put.

Combined with the trivial Collection-based example given in the book I find this definition very helpful and easy to remember.

The final draft is was available for free.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: