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, is called marker interface. Marker interface will not have methods, they are empty interfaces.
It is used to check whether we can perform some special operations on the passed object.
For example:
If class is deriving from java.io.Serializable, then that class object can be serializable else it cannot.
If class is deriving from java.lang.Clonable, then that class object can be cloned, else it cannot.
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.
Write an empty interface and use in the method to check the passed object is of type the interface or not by using “instanceof” operator.
Is empty interface a marker interface?
Depends, if it is using in instanceof operator condition it called marker else it is call empty interface.
Predefined marker interface:
1. Java.lang.Clonable
2. Java.io.Serializable
3. Java.util.RandomAccess
4. Java.rmi.Remote
5. Javax.servlet.SingleThreadModel
6. Java.util.EventListener
It is used to check whether we can perform some special operations on the passed object.
For example:
If class is deriving from java.io.Serializable, then that class object can be serializable else it cannot.
If class is deriving from java.lang.Clonable, then that class object can be cloned, else it cannot.
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.
Write an empty interface and use in the method to check the passed object is of type the interface or not by using “instanceof” operator.
Is empty interface a marker interface?
Depends, if it is using in instanceof operator condition it called marker else it is call empty interface.
Predefined marker interface:
1. Java.lang.Clonable
2. Java.io.Serializable
3. Java.util.RandomAccess
4. Java.rmi.Remote
5. Javax.servlet.SingleThreadModel
6. Java.util.EventListener
No comments:
Post a Comment