This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "marker interface " Watch "marker interface " New topic
Author

marker interface

Chan Apex
Greenhorn

Joined: Oct 26, 2010
Posts: 16
I have confusion in using marker interface..what's the functionality of marker interface..
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Apex han wrote:I have confusion in using marker interface..what's the functionality of marker interface..

They are interfaces with no methods. They tell the compiler to treat the classes implementing them differently. They usually used to categorize the classes based on their purpose. Good examples of these are: Serializable , Clonable.

Found an useful link: Are Marker Interfaces Dead?

Mohamed Sanaulla | My Blog
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

mohamed sanaullah wrote:They tell the compiler to treat the classes implementing them differently.


No. They do not tell the compiler anything. They are not magical in any way. For every use of a marker interface -- Serializable, Cloneable, or any other -- there is plain old Java code somewhere doing something like



That is all. Compilers know nothing about them. The JVM itself knows nothing about them.


Found an useful link: Are Marker Interfaces Dead?


Although some of what this article says is true, it contains the mistakes made in the post above, so far from considering it useful, I'd consider it harmful.


[Jess in Action][AskingGoodQuestions]
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Thanks a lot for clearing the doubt. I knew that they are empty interfaces and had a fair idea about it. But yeah its foolish of me to actually believe most of the article. Considering it was on DZone- I thought it would have relevant information.
 
 
subject: marker interface