Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Java theory and practice: Generics gotchas

Generic types, added in JDK 5.0, are a significant enhancement to type safety in the Java language. However, some aspects of generics may seem confusing, or even downright bizarre, to first-time users. In this month's Java theory and practice, Brian Goetz

Tutorial Details:

Generic types (or generics) bear a superficial resemblance to templates in C++, both in their syntax and in their expected use cases (such as container classes). But the similarity is only skin-deep -- generics in the Java language are implemented almost entirely in the compiler, which performs type checking and type inference, and then generates ordinary, non-generic bytecodes. This implementation technique, called erasure (where the compiler uses the generic type information to ensure type safety, but then erases it before generating the bytecode), has some surprising, and sometimes confusing, consequences. While generics are a big step forward for type safety in Java classes, learning to use generics will almost certainly provide some opportunity for head-scratching (and sometimes cursing) along the way.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Java theory and practice: Generics gotchas

View Tutorial:
Java theory and practice: Generics gotchas

Related Tutorials:

To jar or not to jar? - JavaWorld - July 1998
To jar or not to jar? - JavaWorld - July 1998
 
Programming Java threads in the real world, Part 1 - JavaWorld - September 1998
Programming Java threads in the real world, Part 1 - JavaWorld - September 1998
 
Messaging helps move Java into the enterprise - JavaWorld January 1999
Messaging helps move Java into the enterprise - JavaWorld January 1999
 
Behold the power of parametric polymorphism - JavaWorld February 2000
Behold the power of parametric polymorphism - JavaWorld February 2000
 
Java threads may not use all your CPUs - JavaWorld August 2000
Java threads may not use all your CPUs - JavaWorld August 2000
 
Alternative deployment methods, Part 2: The best of both worlds - JavaWorld July 2000
Alternative deployment methods, Part 2: The best of both worlds - JavaWorld July 2000
 
Double-checked locking: Clever, but broken - JavaWorld February 2001
Double-checked locking: Clever, but broken - JavaWorld February 2001
 
Become a programming Picasso with JHotDraw - JavaWorld February 2001
Become a programming Picasso with JHotDraw - JavaWorld February 2001
 
J2ME: The next major games platform? - JavaWorld March 2001
J2ME: The next major games platform? - JavaWorld March 2001
 
JavaMail quick start
JavaMail quick start
 
Build database-powered mobile applications on the Java platform
Build database-powered mobile applications on the Java platform
 
Implement Design by Contract for Java using dynamic proxies
Implement Design by Contract for Java using dynamic proxies
 
Check out three collections libraries
Check out three collections libraries
 
Good, but obsolete
Good, but obsolete
 
Introducory article
Introducory article
 
J2EE Connector Architecture
J2EE Connector Architecture Introduction If you\'ve ever had to integrate legacy data, data sources, or functionality with a new application, you\'ve no doubt faced a number of challenges: for instance, figuring out how to connect to legacy systems, m
 
Fixing the Java Memory Model, Part 1
JSR 133, which has been active for nearly three years, has recently issued its public recommendation on what to do about the Java Memory Model (JMM).
 
Java theory and practice: Kill bugs dead
Inspection tools like FindBugs provide a second layer of defense against common coding errors.
 
Write custom appenders for log4j
The Apache Software Foundation's log4j logging library is one of the better logging systems around. It's both easier to use and more flexible than Java's built-in logging system.
 
Java theory and practice: Generics gotchas
Generic types, added in JDK 5.0, are a significant enhancement to type safety in the Java language. However, some aspects of generics may seem confusing, or even downright bizarre, to first-time users. In this month's Java theory and practice, Brian Goetz
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.