Friday, 22 April 2016

What are Marker / Tagging / Null interfaces ?


Marker interfaces are a mechanism of asserting a fact about a class, without adding any functionality to it. As such, they represent metadata about that class.

Examples
java.io.Serializable
asserts that objects that implement it may be serialized using java.io.ObjectOutputStream.

java.lang.Clonable
indicates that the objects clone method may be called (A different approach to disallow certain calls is taken by Collection.remove: it throws an exception if it is called on an object that does not support it.)

java.rmi.Remote
indicates that methods may be called from remote JVMs

java.util.EventListener 
used for event listener classes

java.util.RandomAccess 
indicates to the JVM the most performant way to iterate through a List

javax.ejb.EnterpriseBean 
serves as parent for the various EJB interfaces that actually do include methods


javax.servlet.SingleThreadModel
states that this class should not be called for multiple threads concurrently

Marker interfaces are a misuse of interfaces, and should be avoided.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.