This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Doubt abt Serializable,Set,Cloneable Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Doubt abt Serializable,Set,Cloneable Interface " Watch "Doubt abt Serializable,Set,Cloneable Interface " New topic

Doubt abt Serializable,Set,Cloneable Interface

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
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 interface.

How it is Possible ? Tell me some Idea?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
You can read this thread for a discussion on this:

ASCII silly question, Get a silly ANSI.
I agree. Here's the link:
subject: Doubt abt Serializable,Set,Cloneable Interface
It's not a secret anymore!