简体   繁体   中英

Best way to mark an inherited class as NOT serializable

If I inherit from a class that is serializable but I specifically do not want my class to be serializable; what's the best way to strictly prevent serialization?

If there was a method in java.io.Serializable maybe I could throw an exception, but Serializable is empty.

From the documentation

Serialization of an object can be prevented by implementing writeObject and readObject methods that throw the NotSerializableException. The exception will be caught by the ObjectOutputStream and abort the serialization process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM