Archived

This forum has been archived. Please start a new discussion on GitHub.

Intializing members of a slice generated class

Hi there,

Howdy. I've a question on intializing members of a slice generated class.

How are sequences intialized. Do we need to check for null everytime before we add something to it or is there any other way of initializing these members.

Thanks,
Venkat

Comments

  • mes
    mes California
    Which language mapping are you referring to? Java?

    Java initializes reference members to null by default, and the Slice mapping for Java doesn't alter that behavior. The Ice run time interprets a null sequence or dictionary member as an empty container, so there is no need to initialize the member before marshaling if you plan to leave it empty.

    Take care,
    - Mark
  • Hi Mark,

    Thanks for the reply. Yes, Java is the programming language.

    I've mapped the sequence as:

    ["java:type:java.util.ArrayList"] sequence<Foo> FooList;

    If I'm adding objetcs into FooList, I''ll need to check for NULL in the code before I add into that List. Is there any way to specify defaults or some callback to initialize these types.

    Thanks,
    Venkat
  • mes
    mes California
    Hi,

    I'm afraid there is no way to change the initialization behavior of the generated code.

    Take care,
    - Mark