A Slice enum type maps to the Java
enum type. Consider the following example:
The value and
convert methods act as an accessor and a modifier, so you can read and write the value of an enumerated variable as an integer. If you are using the
convert method, you must make sure that the passed value is within the range of the enumeration; failure to do so will result in an assertion failure:
The static members such as _Apple that supply the integer values of each enumerator are retained for backward compatibility with the Java2 mapping.
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).
See Section 10.16.2 for information on the Java2 mapping for Slice enumerations.
Slice structures map to Java structures with the same name. For each Slice data member, the Java class contains a corresponding public data member. For example, here is our
Employee structure from
Section 4.9.4 once more:
For each data member in the Slice definition, the Java class contains a corresponding public data member of the same name. Refer to
Section 10.16.4 for additional information on data members.
The equals member function compares two structures for equality. Note that the generated class also provides the usual
hashCode and
clone methods. (
clone has the default behavior of making a shallow copy.)
The Java class also has a default constructor as well as a second constructor that accepts one argument for each data member of the structure. This constructor allows you to construct and initialize a structure in a single statement (instead of having to first instantiate the structure and then initialize its members).
This definition simply corresponds to the Java type Fruit[]. Naturally, because Slice sequences are mapped to Java arrays, you can take advantage of all the array functionality provided by Java, such as initialization, assignment, cloning, and the
length member. For example:
See Section 10.16 for information on alternate mappings for sequence types.
As for sequences, the Java mapping does not create a separate named type for this definition. Instead, the dictionary is simply an instance of the generic type
java.util.Map<K, V>, where
K is the mapping of the key type and
V is the mapping of the value type. In the example above,
EmployeeMap is mapped to the Java type
java.util.Map<Long, Employee>. The following code demonstrates how to allocate and use an instance of
EmployeeMap:
See Section 10.16 for information on alternate mappings for dictionary types.