Java theory and practice: Going wild with generics

From: IBM developerWorks Worldwide  read times: 85


Provided by yangyi at 2008-05-11 22:40:21


Level: Advanced

Brian Goetz (brian.goetz@sun.com), Senior Staff Engineer, Sun Microsystems

06 May 2008

One of the most complicated aspects of generics in the Java™ language is wildcards, and in particular, the treatment and confusing error messages surrounding wildcard capture. In this installment of Java theory and practice, veteran Java developer Brian Goetz deciphers some of the weirder-looking error messages emitted by javac and offers some tricks and workarounds that can simplify using generics.

Generics have been a controversial topic ever since they were added to the language in JDK 5. Some say they simplify programming by extending the reach of the type system and therefore the compiler's ability to verify type safety; others say that they add more complexity than they're worth. We've all had a few head-scratching moments with generics, but far and away the trickiest part of generics is wildcards.

Wildcard basics

......

Please access the below link to view the full content.

Original link: http://www.ibm.com/developerwork...