WE know that Serializable,Set,Cloneable Interface have no
members.But by Implementing this the classes get some Features .
example a class can get Serializability by implementing the java.io.Serializable interface.
How it is Possible ? Tell me some Idea?
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
posted
0
These are "marker" interfaces which have been discussed around the ranch quite a bit the last few days. Most folks see them as an abuse of the interface feature of the language because they define no behavior. Some like Cloneable are even worse because the behavior method is there with or without the interface.
Markers are there to declare an object's interest in participating in something. If you implement serializable that means your class is willing to be serialized. The code that does the serializing can go through a graph or collection of objects and test "if (object instanceof Serializable)" to decide which objects to serialize. The serializer code won't call any methods on the object it's serializing; the presence of the interface is all it needs to know.
Java 5 introduced a new way to declare meta-data like that, so it's considered a bad practice to write new marker interfaces in that release or later.
Set, by the way, defines a ton of methods and doesn't belong in your list. I'm sure somebody will chime in with the correct list of marker interfaces in the standard libraries.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Stuart Ash
Ranch Hand
Joined: Oct 07, 2005
Posts: 637
posted
0
You can read this thread for a discussion on this: