Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialization Concept In Java with Composition

Tags:

java

If an object is going to be serialized will it be possible to serialize its data member(which are also objects that is composition).
If yes then in which order the state of those objects will be retrieved?

like image 553
Hammad Hassan Avatar asked Nov 22 '25 17:11

Hammad Hassan


1 Answers

If they are also Serializable then, yes otherwise you'll get a NotSerializableException. If you explicitly want to not serialize a member object then declare it as transient.

Regarding the order, I don't get what you mean by that. If you read a serialized object you'll get it in the exact same state it had at serialization.

like image 200
A4L Avatar answered Nov 25 '25 06:11

A4L