• 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

Marker Interface???

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the use of a marker interrface if it has no contents???
eg. Serializable interface.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This gets asked a lot. Search the "Java in General (beginner)" forum, you'll find plenty of answers.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

It's not like that 'marker interface' does nothing? If you dig inside this 'Serializable' interface, you will come to know how does this work. There are 'writeObject' and 'readObject' kind of methods hidden behind the scene.

regards
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ravinder S Edhan:

If you dig inside this 'Serializable' interface, you will come to know how does this work.



Ehm, no you won't. It is a marker interface, it has no source code that does anything. Below is a truncated version of the source code for Serializable (I've removed the comments to save space):
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java in General (Beginner).
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A marker interface is there just so we can ask an object if it has the marker. In this case a serializer might have a whole collection of objects or one object that has references to a bunch of others. The serializer can ask each object "Do you want to be serialized?" If the marker interface is not present, the serializer skips it.

Do you know how to test if an object implements an interface? See if you can find a Java operator to do the job!
 
reply
    Bookmark Topic Watch Topic
  • New Topic