开发者

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 seriali开发者_开发知识库zable; 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜