Marker Interface means they do not have any methods. But Clonable interface has clone() method, Serializable Interface has readObject() and witeObject() methods. How ?
Neither Serializable nor Cloneable has any methods (check their javadocs). That there are methods related to their function that are not part of the actual interfaces indicates a screwed-up design.
Well, I can see one reason why the methods are not in the interface - that requires them to be public. For Cloneable / clone() I still don't see any problems with that. readObject / writeObject however are intended solely for the serialization mechanism. That's why they're private. If they are part of the interface then they must become public, and any code can call them. For writeObject that probably isn't a real problem, but readObject may leave the object in an inconsistent state, especially if the passed ObjectInputStream's current data does not represent the object.
On a related note: why doesn't ObjectOutputStream.writeObject take Serializable as its parameter instead of Object? Any non-serializable object will lead to an exception, so why not limit it through the compiler?
Post by:autobot
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, the permaculture playing cards