wood burning stoves 2.0*
The moose likes Java in General and the fly likes Markable Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Markable Interface" Watch "Markable Interface" New topic
Author

Markable Interface

KasiMurugan Ramasamy
Ranch Hand

Joined: Jan 30, 2005
Posts: 125
Hai Friends,

I understand about markable interface is,

Its a interface, giving instruction to the compiler to provide default behaviour of a function.

Example Cloneable and Serializable.

If we implement cloneable, the compiler will provide the default clone object by using reflection(all instance variables with current values for the new Object).

So i understand that markable interface is to provide default behaviour.

So we can't write our own Markable interface. Because compiler doesn't know how to provide default behaviour.

Hai Friends, Please correct me if iam Wrong.


Thanks & Regards
Kasimurugan (SCJP1.4, SCBCD1.3), Preparing SCWCD1.4
Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 356
First things first, I wouldn't say markable, but marker interface. Markable could mean, that you can mark this interface.

Secondly, you can make your own marker interface. You can always ask if given class implements given interface (obj intanceof Markable) ;-)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41104
    
  45
The JavaIntermediateFaq talks a bit about marker interfaces. The bottom line is, you shouldn't create new ones. These days, use annotations instead.
[ April 02, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Its a interface, giving instruction to the compiler to provide default behaviour of a function.


Not quite right. A marker interface does nothing at all and the compiler does nothing but "mark" the class as implementing the interface. Its only value is that later you can check "object instanceof Interface" and find out whether or not it is present.

All that tricky reflection stuff to serialize an object is provided by the object streams. They check to see if the marker is present and throw an exception if not.

Does that make sense?


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
 
Don't get me started about those stupid light bulbs.
 
subject: Markable Interface
 
Similar Threads
clonning
Marker Interface
Cloning in java
Markable Interface!!!
Why serializable interface is called as Markable ?