File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How does marker interfaces work?" Watch "How does marker interfaces work?" New topic

How does marker interfaces work?

Siddharth bal sharma

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.
| implements
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Welcome to JavaRanch.

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

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.

Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

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.


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:
subject: How does marker interfaces work?
jQuery in Action, 3rd edition