aspose file tools*
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
Author

Marker interface

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Hi,
I did not understand use of marker interfaces and following statement. I read like
'marker interfaces just tell the compiler that the objects of the classes
implementing the interfaces with no defined methods need to be treated differently.(ex cloneable, serializable)

'Any ideas, suggestions, resources, links, sample code highly appreciated. Thanks in advance
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
gudim gudi wrote:
Any ideas, suggestions, resources, links, sample code highly appreciated.


A marker interface is an empty interface (has no methods). It's used as a tag to identify objects at runtime using for example the instanceof keyword, like


Note that using marker interfaces is a quite questionable practice and you should avoid introducing your own.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

A marker interface is a (mostly obsolete) way of providing meta-data about instances of a particular type.
For instance, having a class implement java.io.Serializable is a way to tell the JVM "Hey, my instances are eligable for object serialization, so if they get passed to an ObjectOutputStream, you can work your serialization magic and not throw a NotSerializableException, mkay?".
Nowadays, annotations would be the preferred way to specify meta-data.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41880
    
  63
Also see http://faq.javaranch.com/java/JavaIntermediateFaq#marker


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marker interface