Thursday, July 25, 2013

Java Generics: Technical Book Review

This post is a book review (as part of O'Reilly Blogger Program) of the following book:
  1. Name: Java Generics
  2. Authors: Maurice Naftalin, Philip Wadler
  3. Released: 2006
It's perhaps too late to be reviewing this book, as technical books quickly become outdated. The book was written at the time of a Java release that  marked the "new beginnings" of the formidable Java platform, the Java 5 release, back in 2005. This book review is written in 2013. Generics are an inseparable part of Java Programming Language. Though you'd like to think that it were (somehow) optional to know Generics, it's not the reality. You must be thorough with Generics. I agree that not all of us are library or API designers/implementors, but all of us are users of Java API; and a well-written, "modern" Java API uses Generics heavily. As a result, it quickly becomes imperative to know what Java Generics are.

And if you want to understand Generics, this is the book to get and read. Look no further. The treatment of Generics has not changed (and perhaps will not change) across Java releases. What was true in 2006 about them will be true for quite some time (with minor improvements). And both Naftalin and Wadler have done an exceedingly good job of providing a thorough, lively and almost perfect treatment of this arguably the most divisive Java language feature.

The prerequisite to reading this book (like, perhaps any other book) is to look at both Generics as a concept and their particular implementation adopted by the Java Platform with an open mind. If you have preconcived notions about this (which is not bad), this book is not for you. You should then be on the Java Community Process (JCP) mailing list about Generics.

I appreciate this book mainly because it tries to "inform", not "impress". Many (even popular) technical books tend to do the opposite. With lucid examples, the book helps getting to the bottom of the "whys". It also brings out the synergy between the Java 5 language features that makes the whole greater than just the sum of its parts. After/while reading the book, you might see how the controversial autoboxing/unboxing, varargs methods, the foreach loop work in unison to deliver toward a common goal -- typesafe collections of Java objects.

It's likely that you just hate the compile-time type safety. Perhaps you come from a refreshing and liberal dynamic scripting language like JavaScript and believe that compile-time type safety does not alleviate you of testing your code. You should then consume Generics as a necessary evil when programming in Java. But even then, if you are willing to accept that type safety has some benefits especially in the context of the Java programming language, read this book.