The signature for readObject is:
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException;
which takes in a reference of a concrete class type.
The signature for readExternal is:
void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
which takes in a reference of an interface type.
So why this discrepency? Is it just an oversight?
ObjectInputStream
has several methods not in ObjectInput
that are used specifically to support the default serialization mechanism. Therefore, serialization needs to come from an ObjectInputStream
, but externalization can come from any ObjectInput
.
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