Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Serialization readObject input vs readExternal input

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?

like image 997
shrini1000 Avatar asked Nov 05 '22 07:11

shrini1000


1 Answers

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.

like image 174
Russell Zahniser Avatar answered Nov 09 '22 11:11

Russell Zahniser