Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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

marker interfaces

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What really is the use of marker interfaces if they do not have any method definitions?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before Java 5, they were a substitute for class level annotations.
 
Marshal
Posts: 69874
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You are probably right about "what is the use?" There is more information about marker interfaces in these FAQ, with another useful link. You will have to scroll down the FAQ a bit to find marker interfaces (also called tagging interfaces).
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still dont get it. To quote java faqs

Marker interfaces are a misuse of interfaces, and should be avoided.



Why? And How have annotations made things better?
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by rakesh sugirtharaj:
I still dont get it. To quote java faqs



Why? And How have annotations made things better?


Because interfaces should describe functionality - the methods an object will have implemented and how they behave. Additionally, they can be used (abused as well?) for storing constants, like javax.swing.SwingConstants.

Annotations on the other hand give information about a class, method, field, etc (including annotations themselves). Is it deprecated, does the method override another method, etc. Marker interfaces like Serializable and Cloneable do the exact same thing, and could (should) be replaced by annotations like @Serializable and @Cloneable, since they give information about the class.
They remain because of backwards compatibility.

Now what Sun maybe should have done is start using annotations, make the marker interfaces deprecated and have the JVM check for presence of either (as to not break old code). Since they haven't, these marker interfaces will not be removed since everybody will continue using them.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Marker interfaces which doesn't have any methods i.e. indicates a rule or protocal.If implements those marker interfaces ,compiler understand and supply by seeing neccessary environment to that classes whichever implements marker interfaces.

Thank you.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic