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 use of empty interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "use of empty interface" Watch "use of empty interface" New topic

use of empty interface

khateeb syed

Joined: Jun 25, 2005
Posts: 9
I would wish to know if we can have an empty interface, and what is the use of having such?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15083

Yes, the standard Java library even contains some empty interfaces, for example Serializable and Cloneable. Such interfaces are often called marker interfaces.

Some links:
The Purpose of the Marker Interface
Marker interface pattern

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Marker interfaces are used for no other reason than to inadvertantly introduce a design flaw. Specifically, the specification of metadata (which is all a "marker" interface is) by using the inappropriate language construct (an interface). Since 1.5, we have annotations for that purpose. Before then, you simply have to resort to the use of javadoc for specification of metadata on your types (unfortunately, this data is lost at compile-time). Don't abuse interfaces, be nice. Interfaces are for interfacing, metadata is something else.

Tony Morris
Java Q&A (FAQ, Trivia)
I agree. Here's the link:
subject: use of empty interface
It's not a secret anymore!