aspose file tools*
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
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: 14153
    
  18

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)
 
Don't get me started about those stupid light bulbs.
 
subject: use of empty interface