Marker interface:
- The interfaces using which we explicitly mention or mark certain properties to the object are known as marker interface.
- An interface that is used to check / mark / tag the given object is of a specific type to perform a special operations on that object.
- Marker interfaces will not have methods , they are empty interfaces.
Need of marker interface:
- It i used to check , whether we can perform some special operations on the passed object
- For ex: using serializable interface we can explicitly mention that object of a class is transferable. else it can not.
- If a class is deriving form java.lang.Cloneable interface then that object can be cloned, else it can not
- In side those particular methods , that method developer will check that the passed object is of type the given interface or not by using "instanceof" operator.
Predefined marker interfaces:
- java.lang.Cloneable
- java.io.Serializable
- java.util.RandomAccess
- java.util.Eventlistener
- java.rmi.Remote
- java.servlet.SingleThreadModel
No comments