July 05, 2012

Marker interface does not have any methods, Then how it is work ?


Java compiler design like this...

According to client requirement, design few things. so, we won't estimate which scenario face in realtime. so, java interduce one interface , that is markar.

Here marker means one tag(ex: price rate tag  with any product).

Here only inform the compiler, this is markar. Based on the requirement compiler design...

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.
e.g.  Suppose you want to persist (save) the state of an object then you have to implement the
Serializable interface otherwise the compiler will throw an error. To make more clearly understand the concept of marker interface you should go through one more example.  

Suppose the interface Clonable is neither implemented by a class named Myclass nor it's any super class, then a call to the method clone() on Myclass's object will give an error. This means, to add this functionality one should implement the Clonable interface. While the Clonable is an empty interface but it provides an important functionality.

No comments:

Post a Comment

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts