java - Will serialization save the superclass fields? -


this question has answer here:

my subclass implements serializable, superclass not.

both subclass , superclass contain variables need saved part of state of subclass.

will serialization save superclass fields?

a superclass fields cannot serialized if not serializable.here summary of rules of java serialization:

  • an object serializable if class or superclass implements serializable (or externalizable) interface.

  • an object serializable (itself implements serializable interface) if superclass not. however, firstsuperclass in hierarchy of serializable class, not implements serializable interface, must have no-arg constructor. if violated, readobject() produce java.io.invalidclassexception in runtime.

  • the no-arg contructor of every non-serializable superclass run when object deserialized. however, deserialized objects? constructor not run when deserialized.

  • the class must visible @ point of serialization.

  • all primitive types serializable.

  • transient fields (with transient modifier) not serialized, (i.e., not saved or restored). class implements serializablemust mark -transient fields of classes not support serialization (e.g., file stream).

  • static fields (with static modifier) not serialized.

  • if member variables of serializable object reference non-serializable object, code compile rumtimeexceptionwill thrown.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -