Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Getting Started with Enumerated Types

By Brett McLaughlin
2005-04-22


Use Them, But Don't Abuse Them

One of the dangers of learning a new version of any language is the tendency to go crazy with new syntactical structures. Do that and suddenly your code is 80 percent generics, annotations, and enumerations. So use enumerations only where they make sense. Where, then, do they make sense? As a general rule, anywhere constants are in use, such as in places you are currently using the switch code to switch constants. If it's a single value (for example, an upper bound on a shoe size, or the maximum number of monkeys that can fit in a barrel), leave the constant as it is. But if you're defining a set of values, and any one of those values can be used for a certain data type, enumerations should be a perfect fit.

Tutorial Pages:
» Represent Constants in a Typesafe Manner Using Java 5.0
» Defining an Enum
» Working with Enumerated Values
» Enums and Collections
» Going Further
» Use Them, But Don't Abuse Them
» Resources


First published by IBM developerWorks


 | Bookmark
Related Tutorials:
» All about JAXP, Part 1
» Make Database Queries Without the Database
» Load List Values for Improved Efficiency
» 2 Ways To Implement Session Tracking
» A Simple Way to Read an XML File in Java
» Develop Aspect-Oriented Java Applications with Eclipse and AJDT

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources