Preliminary documentation for Ice 3.7.1 Beta. Do not use in production applications. Refer to the space directory for other releases.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Here is the definition of our EmployeeMap once more:

Slice
dictionary<long, Employee> EmployeeMap;

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<KV>, 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:

Java Compat
java.util.Map<Long, Employee> em = new java.util.HashMap<Long, Employee>();

Employee e = new Employee();
e.number = 31;
e.firstName = "James";
e.lastName = "Gosling";

em.put(e.number, e);

The type-safe nature of the mapping makes iterating over the dictionary quite convenient:

Java Compat
em.forEach((num, employee) ->
    {
        System.out.println(employee.firstName + " was employee #" + num);
    });

Alternate mappings for dictionary types are also possible.

See Also

  • No labels