File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
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

Joined: Mar 10, 2008
Posts: 1951

A marker interface is a (mostly obsolete) way of providing meta-data about instances of a particular type.
For instance, having a class implement 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

Joined: Mar 22, 2005
Posts: 42965
Also see
I agree. Here's the link:
subject: Marker interface
It's not a secret anymore!