aspose file tools*
The moose likes Java in General and the fly likes disadvantages of marker interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "disadvantages of marker interface" Watch "disadvantages of marker interface" New topic
Author

disadvantages of marker interface

anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
What are the disadvantages of marker interface, if any?
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Look at here


Life is easy because we write the source code.....
anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
@Pramod

The link you shared is very obscure Could you please conclude it in more undersatndable language about What are the disadvantages of marker interfaces?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
Is this FAQ any better?
anish jain
Ranch Hand

Joined: Feb 03, 2010
Posts: 129
Campbell Ritchie wrote:Is this FAQ any better?


That link, shared by you, only tells that Annotation is better than using Marker interfaces..but it doesn't tell us what are the disadvantages of using marker interface?

Could you please give me some relevant information regarding my question?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

There are no disadvantages to marker interfaces, except that they clutter your code.

The point is that you shouldn't use them, because they have no advantages whatsoever.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hi,

Do you also disagree with the use of marker interfaces in validation, such as JSR-303 where marker interfaces are used within annotations to specify which validation should be carried out?

Sean


I love this place!
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Why is it necessary this is done using interfaces?
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Stephan van Hulst wrote:Why is it necessary this is done using interfaces?

It is not unless you wish to use groups, which is where the link pointed to.
Sean
Sreelatha Sankaranarayanan
Greenhorn

Joined: Dec 10, 2010
Posts: 9
Annotations and marker interfaces are pretty much used for the same purpose, however annotations can be used on class,method or variable whereas marker interfaces can be used only on classes , maybe the only disadvantage of marker interfaces over annotations.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Sean, my point is, couldn't they have implemented it without forcing you to use interfaces?

The link you pointed me to is a bit much for me to go over it right now, and I'm not familiar with the validation described therein.

You can engineer any situation to require marker interfaces, and it gives them a purpose, but not an advantage. I think the use of marker interfaces is pure abuse of the language.
The sheer fact that they are named separately because they are being used for a different purpose than they were originally intended, doesn't speak in favour of them.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41885
    
  63
One of these days I'll change the forum software to force anyone who wants to use "marker interface" in the subject line of a new post to read at least 10 previous topics on the subject (which are easily found through the site search).



Ping & DNS - my free Android networking tools app
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  16

Haha,
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14156
    
  19

Marker interfaces, such as Serializable, have the same function as annotations - they are used to specify certain properties (metadata) of classes, methods, fields etc.

I can understand Stephan when he says that this is abuse of the language - the main purpose of interfaces is to specify a set of methods that a class must implement. Somebody came up with a different usage - for providing metadata, and so the idea of marker interfaces was born.

The main purpose of annotations is exactly to provide metadata, so you should prefer to use annotations for that, and not marker interfaces.

Annotations are also more flexible than marker interfaces. Annotations can have parameters and can not only be applied to classes, but to methods, fields etc. as well. So, there you have a disadvantage of marker interfaces, when compared to annotations.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: disadvantages of marker interface