File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Marker Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Marker Interface" Watch "Marker Interface" New topic
Author

Marker Interface

veeramani velayutham
Greenhorn

Joined: Dec 10, 2004
Posts: 11
marker interface does not contain method and variable. then why are we using marker interface.
sanjeevmehra mehra
Ranch Hand

Joined: Aug 21, 2004
Posts: 75
Marker interface does not have any member but there is always reason to use it.
it's tag or green signal to allow to perform the task for which we inherit class/interface from it.


thanks & regards,<br />Sanjeev.
veeramani velayutham
Greenhorn

Joined: Dec 10, 2004
Posts: 11
can u plz. explain in detail.
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
<p>Personally I think it's a really poor idea: very bad OO design as it splits responsibility.

<p>Probably the most obvious example is with java.lang.Object and java.lang.Clonable: Object has a clone method but it wont work unless the class also implements Clonable.

<p>The way it should have done was to place the clone method on the Clonable interface and have a protected clone helper method on Object. One of several poor OO design decisions in Java I'm afraid (my other big bug bears if you're interested are: deprecated methods are never deleted and pretty much the whole of Java 1.5

Edward
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

clone() is a bad design, but I wouldn't say that marker interfaces in general are always a bad thing.

When a class implements a marker interface X, it's just a way of saying "I support some feature X" which isn't expressed as a set of methods. For example, implementing the java.io.Serializable marker interface is a signal to the JVM that a class will allow itself to be serialized.

Whenever there's a marker interface X, there's code someplace which says



[Jess in Action][AskingGoodQuestions]
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
I have to disagree: serializable should implement an interface with a "serialize" method. A default can be provide by Object.
Pratik Thakare
Greenhorn

Joined: Aug 29, 2012
Posts: 3
I am a beginner i might be wrong but according to me

Marker interface is also called as empty interface. it does not consist of any method. example Serializable and clonable are two marker interface.

if you are using Serializable or clonable interface it means (it indicates) that your class object are is serializable or clonable.

It can be used as an indicator.

IF i am wrong please reply back
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

veeramani velayutham wrote:marker interface does not contain method

actually it has...
JLS =>

If an interface has no direct superinterfaces, then the interface implicitly declares a public abstract member method m with signature ss, return type rr, and throws clause t corresponding to each public instance method mm with signature ss, return type rr, and throws clause tt declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface. It is a compile-time error if the interface explicitly declares such a method m in the case where m is declared to be final in Object.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Pratik Thakare wrote:
if you are using Serializable or clonable interface it means (it indicates) that your class object are is serializable or clonable.

If a class implements Serializable and it dont contain any other object which is not serializable, then yes, its object can be serializable
Serialization is a deep copy process. so all object references from the object also should be Serializable.
 
Consider Paul's rocket mass heater.
 
subject: Marker Interface
 
Similar Threads
marker interface
Java
What is advantage of marker interface?
Marker Interface
Marker Interface purpose