Greetings,
> How would you handle a Version annotation indicating the compatibility of a
> deceleration or value. E.g.
>
> @Version("2.0") Widget createWidget(String value) { ... }
>
> @Version("2.0") could mean that the createWidget method only appears in the
> 2.0 version, or it could mean that the returned Widget should only be used
> by code that uses the 2.0 API of Widget, in addition to being a 2.0 method.
There are two questions here:
1. How do we determine the target element of Version? Is it the
method or return type?
The answer here is as before, it's determined by the Version
annotation declaration. If it's meta-annotated with @Target(METHOD),
then it's assumed to target the method, if it's meta-annotated with
@Target(TYPE_USE), then it's assumed to target the return type.
The problem that Mike is presenting here, is what if the annotation
contains no Target meta-annotation (bad style!), how should this
annotation be treated? Both proposals here state that this annotation
should be treated as both: a declaration annotation (i.e. targets the
method) and a type annotation (i.e. targets the return type). The
proposals differ however, on whether the annotation should be written
twice in the classpath or only once.
2. What does the annotation Version mean? Is it restricting where the
method appears or how the returned value is used?
The JSR 308 specification is only concerned about which syntactical
Java element the annotation is targeting. Any meaning beyond that is
defined by the annotation/checker writer. In other words, the
specification and compiler makes no assumption on what the annotation
actually means.
I assume that @Version is an illustrated example here, but not
actually found in the JDK or particular library. Do you know of
libraries defining annotations without Target meta-annotation?
Regards,
Mahmood