Marker interface in java
Marker interface is a interface which don’t have any mehtod.It is used to tag the implementing class based on their purpose.Marker interface is a Java interface which doesn’t actually define any fields. It is just used to “mark” Java classes which support a certain capability –the class marks itself as implementing the interface. For example, the java.lang.Cloneable interface.
In java language programming, interfaces with no methods are known as marker interfaces or tagged interface.Marker Interfaces are implemented by the classes or their super classes in order to add some functionality.Marker interfaces are understood by the JVM. The JVM takes care of how to deal with a class that implements that marker interface
Why we use marker interface.
The marker interfaces are used to provide certain functionality to classes you code. Take for instance the Cloneable interface. This interface is implemented by the JVM itself and allows copies of objects to be created without the developer having to write code for this purpose. User written marker interfaces can also be used for inheritance purposes.Marker Interfaces are used to mark the capability of a class as implementing a specific interface at run-time.
Example of marker Interface.
java,lang.Cloneable
java,io.Serializable
java.util.EventListener




Comments
Yes; and you can actually do the same with annotations as well now (to emulate interfaces). Not sure what the advantageous would be though…
Example (in Dutch though):
http://www.jtraining.com/blogs/annotations-nu-ook-voor-jou.html
Now you should use annotations. Interfaces serve a different purpose, and nowadays should not be without methods. You can check implemented annotations at runtime too, see for example http://bill.burkecentral.com/2008/01/14/scanning-java-annotations-at-runtime/
Hi,
What is the difference between an empty interface and an empty abstract class ?
(Other than multiple inheritance)
Hi,
.
Appreciate your efforts in putting this. It would be better to understand if you would have given some more example
Just my thoughts…
Trackbacks