Reputation: 334
If I have main class, that is Serializible
and create instances of other classes (no inheritance) that are not defined as being serializible, will the state of those classes be also preserved along with the state of the main class, if they are not static? I know that constructors of other objects are bypassed, but what about states? And yes, I did search SO and Google, but came out empty handed, so I hope some nice gent will clear this up quickly for me.
Upvotes: 0
Views: 30
Reputation: 531
If there is a reference to an object that is not serializable, a NotSerializableException will be thrown.
When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object.
Source: https://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html
You may work around it, as some answers on SO suggest, e.g. Java Serialization with non serializable parts
Upvotes: 1