June 2004
Intermediate to advanced
848 pages
21h 28m
English
Here's the older approach of simulating enumerations:
class Bread { static final int wholewheat = 0; static final int ninegrain = 1; static final int rye = 2; static final int french = 3;}
You would then declare an int variable and let it hold values from the Bread class, e.g.
int todaysLoaf = Bread.rye;
Using final ints to represent values in an enumeration has at least three drawbacks.
All the compiler tools (debugger, linker, run-time, etc.) still regard the variables as ints. They are ints. If you ask for the value of todaysLoaf, it will be 2, not “rye”. The programmer has to do the mapping back and forth mentally.
The variables aren't typesafe. There's nothing ...
Read now
Unlock full access