java - Why does ObjectOutputStream.readObject() access MyClass.readObject() -


i going through basics of java io , saw that, in order use custom writeobject function in class, has declared private.

private void writeobject(objectoutputstream oos); 

then, when call

oos.writeobject(myclassobject); 

this function looks private writeobject method in myclass , executes it.

my question is: if true, won't violation of data abstraction concept when function can call private method of class? reason feature?

i doing educated guess here.

the way, how serialization works logically tied single object class. not make sense inherit it, forced private.

it violates oo principles, can see reason in approach. because serialization heavily depending on reflection.


Comments