Marker Interfaces in Java are special interfaces which don’t declare any methods inside the interface definition. Because of that, if a class implements the marker interface don’t need to override any methods. What is the use of marker interface in Java?. It implicitly imposes a functionality or characteristic to the implementing class. There are many marker interfaces are already present in the JDK which are often used in the Java programming.
Some of the marker interfaces in Java are
- java.lang.Cloneable
- java.io.Serializable
- java.util.EventListener
A programmer can not create their own marker interfaces as mentioned above. But, it is possible to create the same interfaces like above, by writing the extra code to simulate the behaviour of the marker interface. Only the interfaces defined by JDK will have the functionality, we can not impose compiler to act upon our code. Marker interface itself not a standard term used in JDK, it is used by the authors to indicate a behaviour of certain interfaces.
With the introduction of annotation in Java 1.5, there is no need for the marker interfaces in Java. One can use the annotations to impose a functionality, prior to that these concept is used.