• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How does marker interfaces work?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Siddharth bal sharma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic