This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "use of empty interface" Watch "use of empty interface" New topic
Author

use of empty interface

khateeb syed
Greenhorn

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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
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)
 
Consider Paul's rocket mass heater.
 
subject: use of empty interface
 
Similar Threads
Separators
Interface Q
empty interface
Empty abstract classs vs Empty interface
Marker Interface purpose