J2SE 5.0 introduced many additions to the collections API that you need to be aware of to properly implement generic custom collections that work seamlessly with multiple types and the new "for each" construct.
by Jeff Heaton
October 18, 2005
y last article discussed how to use J2SE 5.0's new collection features, allowing you to designate a specific type to be used with a collection. Additionally, the new "for each" construct lets you access collections without the need for an "iterator". However, that was only half the story. This article shows you how to create collections that are compatible with the latest features of J2SE.
Creating Classes that Support Generics
First you must lean how to create a class that allows a "generic type". This means that whenever your class is instantiated, you can also specify one or more Java types to be associated with that class. To illustrate this, consider this simple example class presented in Listing 1.
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!