November 2005
Intermediate to advanced
304 pages
6h 14m
English
Most applications need to keep track of a finite set of values—constants that represent a set of choices or states in the application. One common Java programming practice is to use static int variables to represent these values. Programs then make decisions by comparing the values of other variables against them. Although the core Java API itself uses this practice, it can lead to serious problems! The following example class returns information about fruits for an imaginary menu-planning system. It shows some of the problems in using int variables to represent enumerated data:
public class FruitConstants ...
Read now
Unlock full access