Marker Interface in Java
Marker Interface is an interface with no method or field or in simple empty interface.The marker interfaces are also called as tag interface
Eg: Serializable, Clonnable, Remote interface.
Another explanation for marker interface is:
“An interface is called a marker interface when it is provided as a handle by Java interpreter to mark a class so that it can provide special behavior to it at run time and they do not have any method declarations”
If Marker interface doesn’t have any method or field what is the use of implementing the marker interface?
When we carefully look into, we can see that, they are used to indicate something to compiler or JVM. So if JVM sees a Class is Serializable it done some special operation on it, similar way if JVM sees one class is implement Clonnable it performs some operation to support cloning. Same is true for RMI and Remote interface. So in short Marker interface indicate, signal or a command to Compiler or JVM. Apart from using built in marker interface for making a class Serializable or Clonnable. One can also develop his own marker interface .Marker interface is a good way to classify code.
No comments:
Post a Comment