This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Why Marker Interface? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why Marker Interface?" Watch "Why Marker Interface?" New topic

Why Marker Interface?

Manikandan Jayaraman
Ranch Hand

Joined: Sep 15, 2004
Posts: 230
Hi All,

When we say that Marker Interface has no methods, why do we need it at all?

Why should we have a interface with NO methods and implement it?

Please answer me! Thanks!

- Mani

Regards,<br />Mani<br />SCJP 1.4 (95%)<br />SCWCD 1.4 (94%)
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

This is asked often. Have a search through the forum, you will find plenty of answers.
[ August 08, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

What is a "marker" interface?
Marker Interface pattern - Marker Interface - Marker Interfaces
The Purpose of the Marker Interface
Maximize your Design ROI with Marker Interfaces and JavaDoc
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

A marker interface is used to inadvertantly introduce a design flaw.
A marker interface is typically better described as "metadata" with some contractual properties associated with it.
For example, you could eliminate the marker interface and introduce a Serializable annotation with associated contract (i.e. in the javadoc), since it is annotations that are the correct tool for metadata, and prior to 1.5, mere javadoc; it has never been interfaces, despite the flaws that are evident in the core API.

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: Why Marker Interface?
It's not a secret anymore!