effective-java

Why are readObject and writeObject private, and why would I write transient variables explicitly?

别等时光非礼了梦想. 提交于 2019-11-26 15:35:07
问题 I am reading the chapter on Serialization in Effective Java . Who calls the readObject() and writeObject()? Why are these methods declared private ? The below is a piece of code from the book // StringList with a reasonable custom serialized form public final class StringList implements Serializable { private transient int size = 0; private transient Entry head = null; //Other code private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeInt(size); //