To quote this link :
Some developers think that the Java compiler understands the tag and
work accordingly. This is not right. The tags actually have no meaning
to the Java compiler or runtime itself. There are tools that can
interpret these tags
.
If the information contained in the annotation is only metadata, why wont my code compile if I annotate wrongly ? That particular annotation should be simply ignored right ?
Edit :
Just to provide an example… A simple JAX-RS web service on Jersey uses an annotation like :
@Path("mypath")
Now, if I change this to :
@Paths("mypath")
OR
@Path(123)
it should NOT stop me from compiling the code according to the above link…
The article is wrong for at least some annotations. Thinks like
@SuppressWarningsand@Overridethe compiler does have very specific knowledge. In fact, the article points this out itself:Quite how it can be used by the compiler if “the tags actually have no meaning to the Java compiler”, I don’t know…
Additionally, even for annotations that the compiler doesn’t attach any semantic meaning to, it will still verify that when you try to specify particular arguments etc, that those arguments have sensible names and types for the annotation you’re using.