Life is easy because we write the source code.....
anish jain
Ranch Hand
Joined: Feb 03, 2010
Posts: 129
posted
0
@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?
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?
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?
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
posted
0
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.
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: 35224
7
posted
2
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).
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.