• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Markable Interface

 
KasiMurugan Ramasamy
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic