Let's say I have a Serializable interface as follows
public interface SomeInterface extends Serializable {
public SomeClass getSomething(String someParameter);
}
Will SomeClass
be Serializable automatically?
To our surprise, our RMI application runs fine even when SomeClass
does not implement Serializable.
Why is this?
Will
SomeClass
beSerializable
automatically? To our surprise, our RMI application runs fine even whenSomeClass
does not implementSerializable
.
No.
Serialization is about serializing the (non-transient) state of an object. The presence of a getSomething
in the signature of some method doesn't require the state of your instance of a SomeInterface
to include a SomeClass
instance.
The method could be implemented to return a newly created SomeClass
, the value of a transient
field, the result of calling a static
method on some other class, or .... null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With