A Slice enum type maps to the Java
enum type. Consider the following example:
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).
Slice structures map to Java classes 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.3 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.)
Structures have a default constructor that default-constructs each data member. This means members of primitive type are initialized to the equivalent of zero, and members of reference type are initialized to null. Note that applications must always explicitly initialize members of structure and enumerated types because the Ice run time does not accept null as a legal value for these types.
If you wish to ensure that data members of primitive and enumerated types are initialized to specific values, you can declare default values in your Slice definition (see
Section 4.9.2). The default constructor initializes each of these data members to its declared value.
Structures also have a second constructor that has one parameter for each data member. This allows you to construct and initialize a class instance in a single statement (instead of first having to construct the instance and then assigning to 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.