A Slice enumeration maps to the corresponding enumeration in Java. For example:
The Java mapping for
Fruit is shown below:
Given the above definitions, we can use enumerated values as follows:
The Java mapping includes two methods of interest. The
value method returns the Slice value of an enumerator, which is not necessarily the same as its ordinal value. The
valueOf method translates a Slice value into its corresponding enumerator, or returns
null if no match is found. Note that the generated class contains a number of other members, which we have not shown. These members are internal to the Ice run time and you must not use them in your application code (because they may change from release to release).
Fruit definition above, the Slice value of each enumerator matches its ordinal value. This will not be true if we modify the definition to include a custom enumerator value:
The table below shows the new relationship between ordinal value and Slice value:
Java enumerated types inherit implicitly from
java.lang.Enum, which defines methods such as
compareTo that operate on the ordinal value of an enumerator, not its Slice value.