Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

marker interface

 
Shrawan Bhageria
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

what is marker interface n why it is used in java ? could any body explain it wth some example ?
Though there are no methods in marker interfaces like java.io.Serializable , how this the serialization will be done.

pl. help
thanks
shrawan

SCJP 1.4,SCWCD 1.4,MCP
SCBCD 1.3(preparing)
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A marker interface is used to indicate to the JVM that a class that implements it has a particular property. With Serializable, it indicates that the class *CAN* be serialized. How serialization then is accomplished is described in the javadocs for Serializable.
There is at least one other marker interface in the JDK, but I can't think of which one it was right now.
 
Shrawan Bhageria
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thanks
but i can't understand what u say
pl. can u explain it wth some example

regard
shrawan
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A marker interface is used to inadvertantly introduce a design flaw.
A marker interface is typically better described as "metadata" with some contractual properties associated with it.
For example, you could eliminate the java.io.Serializable marker interface and introduce a Serializable annotation with associated contract (i.e. in the javadoc), since it is annotations that are the correct tool for metadata, and prior to 1.5, mere javadoc; it has never been interfaces, despite the flaws that are evident in the core API.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic