• Post Reply Bookmark Topic Watch Topic
  • New Topic

what are marker interfaces in java  RSS feed

 
Raghuveer Rawat
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what are marker interfaces in java, why they are said so. how they are different then general interfaces.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A marker interface is a completely empty interface (no methods, no constants) which still means something if you implement it. One example is "Cloneable." If your class implements Cloneable, then the version of clone() inherited from Object knows that it's OK to try to clone your class. If you don't implement this empty interface, clone() throws CloneNotSupportedException.
The only purpose of implementing Cloneable is to tell clone() that it's OK to run. This is what marker interfaces do.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A marker interface is an interface that has no methods or fields.
It is used only to identify the semantics of that interface.
Examples are java.io.Serializable, java.lang.Cloneable etc.
A class implements java.io.Serializable just to tag that that class can be serialized. No methods are implemented in that class.
It is also calles sometimes as a "Tag Interface" or a "Null Interface"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!