This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes How does marker interfaces work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How does marker interfaces work?" Watch "How does marker interfaces work?" New topic
Author

How does marker interfaces work?

Siddharth bal sharma
Greenhorn

Joined: Apr 27, 2006
Posts: 8
I mean, i know its just a hint to the JVM that "ok buddy- its your responsiblity to take care of this special behavior of the object" , but how does it really work?

Is there any call-back mecanism in place , now u might think that marker interfaces dont have any methods so which call back methods! But my marker interface can be extended by another interface X.Now that X implementation is the JVM implementation class or some native implementation or JNI( for serializable)?

small class-dia just to depict what i mean by my question.
extends
X----------->serializable
A
| implements
|
|
someclass
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Welcome to JavaRanch.

You can recognize an object that implements an interface by using "instanceof". If you look at the source of java.io.ObjectOutputStream, you can see lines like "if (obj instanceof Serializable)" that do certain things fro serializable objects, and different things for other objects.


Ping & DNS - my free Android networking tools app
Siddharth bal sharma
Greenhorn

Joined: Apr 27, 2006
Posts: 8
i asked abt how the marker interfaces are implemented i.e. they act as marker for JVM, but how does JVM tales care of it?
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Same way as any other interface a class implements, it lists the class as implementing that interface.
How another class would use a class implementing your marker interface depends entirely on the programmer of that class.


42
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Like Ulf pointed out you use the instanceof operator to check if an object is serialized. Any subclasses that extend the class that you have serialized are also serializable.

Example:


blah b = new blah();

Now - b instanceof Serializable will return true.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does marker interfaces work?