• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marker Interface

 
Nagendhra Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody let me know how do we create a marker interface and how to describe its functionality so that the implementing classes will inherit this functionality...for eg, by implementing serializable interface we are able to make an object as serializable....?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A marker interface tells you something about an object, but since it has no methods there is nothing to implement. For example we can test for Serializable like this:

if ( someObject instanceof Serializable ) ...

But if you decide to implement the serializable interface on a class you're not required to implement any functionality. There are some other rules you're expected to follow, like having a no-argument constructor and making sure the objects referenced by your member variablees are also serializable, but nothing the compiler will check for.

Marker interfaces are now generally considered A Bad Thing and with more modern Java versions we would do well to use Annotations instead.

Did that raise more questions?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic