• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

disadvantages of marker interface

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the disadvantages of marker interface, if any?
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at here
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this FAQ any better?
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is it necessary this is done using interfaces?
 
Sean Clark
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Haha,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic