Some examples (inspired by the Java Enum Tutorial):
Or with a bit of refactoring, you could write the switch like this:
Here is a coin example:
Here is a planet example:
In the "enum Planet" example, there are two lines that define mass and radius methods,
Pasting the sample code into groovyConsole, it seems to run just fine with these two lines commented out. Are they really doing anything useful? I can get at a value with
The mass() method does allow this:
If all it's doing is providing a different way to access the value, shouldn't there also be a pair of methods like:
to allow the following as well?
Powered by a free Atlassian Confluence Open Source Project License granted to Codehaus. Evaluate Confluence today.