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

bglmmzbglmmz Member Joey LvOrganization: PersonalProject: CA system

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

Best Answers

  • mesmes ZeroC Staff CaliforniaMark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Accepted Answer

    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

  • bglmmzbglmmz Joey LvOrganization: PersonalProject: CA system
    Accepted Answer

    Thanks~

Answers

  • mesmes ZeroC Staff CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Accepted Answer

    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

  • bglmmzbglmmz Member Joey LvOrganization: PersonalProject: CA system
    Accepted Answer

    Thanks~

Sign In or Register to comment.