• Post Reply Bookmark Topic Watch Topic
  • New Topic

Marker Inerface  RSS feed

 
sriram sundararajan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serializable is the marker interface in java. This interface will not have any methods, it will act like a flag and jvm identifies and act upon it. My doubt is can build my own Marker interface. If it is possible what is the procedure i need to follow?
Any inputs will be appreciated.
 
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 made meaningful only when some code tests for it; i.e., someplace in the JVM, some code is asking

if (object instanceof Serializable)

and this is what makes Serializable a marker interface. All you have to do is define your empty interface

public interface MyMarkerInterface {}

and then use it accordingly. There's no magic or "marker interface bit" anyplace.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!