Marker Interface

In java language programming, interfaces with no methods are known as marker interfaces. marker interfaces are Serializable, Clonable, SingleThreadModel, Event listener. Marker Interfaces are implemented by the classes or their super classes in order to add some functionality.

Then,
why we need marker interface, if there are no methods??
what kind of contract have marker interface with JVM??

ok here we go............

All the Marker interface are an empty interface but it provides an important functionality.

-> making Clone of any object : is an unsecured operation for JVM
-> writing the state of an object on some media or terminal : is an unsecured operation for JVM

we must implement Clonable interface to call method clone() else exception CloneNotSupportedException

we must  implement Serializable interface to write the state of any object
else exception NotSerializableException

Marker interface indicate, signal or a command to JVM.
 

No comments:

Post a Comment