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....?
posted 9 years ago
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