This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java 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 » Beginning Java
Bookmark "Marker Interface???" Watch "Marker Interface???" New topic

Marker Interface???

Rohit VG

Joined: Oct 26, 2005
Posts: 2
What is the use of a marker interrface if it has no contents???
eg. Serializable interface.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

This gets asked a lot. Search the "Java in General (beginner)" forum, you'll find plenty of answers.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ravinder S Edhan
Ranch Hand

Joined: Dec 15, 2003
Posts: 57

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.

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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):
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Moving to Java in General (Beginner).

[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Marker Interface???
jQuery in Action, 3rd edition