• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

use of empty interface

 
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
 
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.
 
Everybody's invited. Even this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic