Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

marker interfaces

 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • 0
  • 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?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before Java 5, they were a substitute for class level annotations.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • 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
  • 0
  • 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?
 
Rob Spoor
Sheriff
Pie
Posts: 20381
46
Chrome Eclipse IDE Java Windows
  • 0
  • 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.
 
Malayathi Partha Saradhi
Greenhorn
Posts: 10
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic