Archived

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

When compile Slice to Java, how to customize the java class's default constructor?

here is my slice:
["java:getset"]
class MyReq {
string txCode;
string txTime;
};

and here is the java class:
public class MyReq extends Ice.ObjectImpl
{
public MyReq()
{
txCode = "";
txTime = "";
}

...
}

The txCode and txTime have a default value "", but I would like the txCode and txTime has no default value "", so, how to approach this?

Thanks
Joey

Comments

  • mes
    mes California

    Hi,

    It's not possible to modify the default constructor. I'm assuming you'd like to have these members set to null instead of an empty string, but note that the Slice data model doesn't support the concept of a null string. As a convenience, you can set string data members to null and Ice will marshal an empty string, but upon receipt you will always get an empty string.

    If your goal is to model "not set" semantics, I recommend using optional data members instead.

    Regards,
    Mark

  • Thanks~