Search This Blog

Marker Interface


What is Marker interface and why we use it?

As the name suggest an Interface used to mark something is marker interface. A marker interface doesn’t have any field or method declaration in it i.e. marker interface is an empty interface. Serializable, Cloneable, Remote interfaces are examples marker interface .Marker interfaces are implemented to indicate something to compiler or JVM to add special behavior
at runtime with implementing class. So when JVM sees that some class is implementing Serializable it handle that class in different way that you can serialize the object of that class. Java5 introduced us with Annotations which can be used to achieve the functionality of marker interfaces(i.e. to inform compiler to behave in special way for annotated class). Marker interfaces are also called tag interface.

No comments:

Post a Comment