Semantics of object creation / initialization in Java

I'm a C ++ fan who picks up Java for Android apps. In C ++, the canonical way to create and initialize an object would be to fully initialize it in the constructor:

class Message {
  string payload;
  int client;
  // etc.

public:
  Message(string payload, int client)
    : payload(payload)
    , client(client)
  {}
};

This is similar to Java. This gets a little ugly because I want to make certain members const(the best Java can do this final), but usually I can figure it out.

But now I am running libraries, such as FreeHEP-XDR, the interface XDRSerializableindicates a signature:

void read(XDRDataInput in);

, Message, , , void. Message , , , . : XDRDataInput , ( , read). , , final Message, !

Java? , ?

+4
1

, , . , , , , . , , , , a, b.

, java (, ) . , (, javadoc, , , XHRDataInput), ( , , , JavaBeans).

, : , "" . "read", , ( , ), .

+2

Source: https://habr.com/ru/post/1542273/


All Articles