On this page:
Basic Java Mapping for Structures
A Slice structure maps to a Java class 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 once more:
The Slice-to-Java compiler generates the following definition for this structure:
For each data member in the Slice definition, the Java class contains a corresponding public data member of the same name. Note that you can optionally customize the mapping for data members to use getters and setters instead.
equals member function compares two structures for equality. Note that the generated class also provides the usual
clone methods. (
clone has the default behavior of making a shallow copy.)
Java Default Constructors for Structures
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. 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 assign to its members).