I have a class which implements Serializable. Now I extends this class and I want this extended class to be non Serializable. So how to do it?
For example. I have >
As others have made clear, it's not possible for a subclass of a Serializable
class to be non-Serializable
.
If what you want is for the subclass' attributes not to be serialized, one option is to make them all transient.
If you need more than that (you don't want super class fields to be serialized), override writeObject(ObjectOutputStream)
and readObject(ObjectInputStream)
as outlined here - https://web.archive.org/web/20120626144013/http://java.sun.com/developer/technicalArticles/ALT/serialization