I was looking at java.security.BasicPermission API the other day. Why does it have a private method?
private void readObject(ObjectInputStream s) readObject is called to restore the state of the BasicPermission from a stream.
Sorry, I wasn't clear about what I asked. The class is just an example. There are many of them in Java library. All of them are read|write Object method. When they designed this API, why would they add a private method that an application can't use?
readObject is a used by the Java serialization framework when deserializing, to provide support for custom operations. Unlike most private methods, it usually wouldn't be called within the class itself - instead it's called by the framework / JVM, which obviously violates normal expectations somewhat.
See the docs for Serializable for more details.
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