• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what are marker interfaces in java

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are marker interfaces in java, why they are said so. how they are different then general interfaces.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
reply
    Bookmark Topic Watch Topic
  • New Topic