• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of empty interface

 
khateeb syed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic