What is marker interface ? What is the use for that one ?
------------------
suresh
Printable View
What is marker interface ? What is the use for that one ?
------------------
suresh
An empty interface is known as a "marker" interface in Java. A class implementing this has a certain feature/property about it. E.g Serializable interface. Any class implementing this is serializable. Same with Cloneable interface.
Interface containing methods is normal Java interface and these methods must be implemented by any class which wishes to implement that interface.
Hope this helps.
What is the use of empty interface ? From your answer, i think the use for this to identify the class contains serializable or Cloneable etc...
But this is the only use then why they create interface ? They can easily design a java reserved keyword and then implement it...
Why they particularly design a interface to acheice this goal ?:confused:
-------------------
suresh
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.
To let the system know that some action can be formed on a class that implements the marker?
Serializable --> Class be serialized using serialize()
Cloneable --> Class can be cloned using clone()
Marker is an interface without methods examples serializable, cloneable etc.
The use of marker interface is that to indicated the compile that it has to treat the objects implementing marker interface as per the specifications of the marker interface.
Example serializable interface is used to store persistent data.
:o
marker doesnt have methods but they accomplish the task if a class implements the marker interface,Any interface without a method acts like a marker. They just tell the compiler that the objects of the class implementing the marker interface has to be treated differently. Example Its used in the process of serialization. To send an object over network or if the state of the object has to be persisted to a flat file or a database. Deep cloning can be achieved through serialization. This may be fast to code but will have performance.
Hi suresh,
Technically any java object that implements java.rmi.remoteinterface this interface is a marker interface or tag interface, you know which doesn't contain any methods.A marker interface is usually used to indicate a specially features related to our class to the JVM.
regards,
vardhan.