Forums Register Login

Marker Interface methods ?

+Pie Number of slices to send: Send
Marker Interface means they do not have any methods. But Clonable interface has clone() method, Serializable Interface has readObject() and witeObject() methods. How ?
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

Ulf Dittmer wrote:That there are methods related to their function that are not part of the actual interfaces indicates a screwed-up design.



Quoted for truth.
+Pie Number of slices to send: Send
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?
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
https://gardener-gift.com


reply
reply
This thread has been viewed 1219 times.
Similar Threads
How does a class gets that functionality from marker interface?
Is Runnable a marker interface ?
Use of marker interface
What is advantage of marker interface?
serializable interface
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:56:13.