Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Marker Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Marker Interface" Watch "Marker Interface" New topic
Author

Marker Interface

Nagendhra Kumar
Greenhorn

Joined: Aug 28, 2006
Posts: 5
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

Joined: Jan 29, 2003
Posts: 8791
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?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Marker Interface
 
Similar Threads
how do we achieve serialization?
Marker Interface
Marker Interfaces
How to write our own Marker Interface?
Marker Interface