Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations require @Target for JSR-308 compatibility #25

Open
GoogleCodeExporter opened this issue Apr 22, 2015 · 1 comment
Open

Annotations require @Target for JSR-308 compatibility #25

GoogleCodeExporter opened this issue Apr 22, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

Hi.

I've been using javax.annotation.Nullable and javax.annotation.Nonnull in my 
code, as they're IDE neutral and capable of being recognized by several popular 
tools.

However, Java 1.8 requires that inner-class and qualified type references use 
an annotation syntax which is compatible with it's new JSR-308 support (e.g. A 
"@Nullable MyOuterClass.MyInnerClass" parameter becomes "MyOuterClass.@Nullable 
MyInnerClass").

Doing that with the JSR-305 annotations causes javac to complain "annotation 
type not applicable to this kind of declaration", and Eclipse to complain 
"Annotation types that do not specify explicit target element types cannot be 
applied here".

This is because the JSR-305 annotation definitions lack a declaration of the 
form:

@java.lang.annotation.Target({ java.lang.annotation.ElementType.FIELD, 
java.lang.annotation.ElementType.METHOD, 
java.lang.annotation.ElementType.PARAMETER, 
java.lang.annotation.ElementType.LOCAL_VARIABLE })

While JSR-305 may not currently be moving forward as an official standard, it's 
still of great value to many people as a defacto one, so if there is any way 
@Target could be added in order for that to continue with Java 1.8 until 
something more official comes along, it would be most excellent.

Many thanks for your consideration.

Original issue reported on code.google.com by [email protected] on 3 Jan 2014 at 12:59

@GoogleCodeExporter
Copy link
Author

Correction - It appears as though @Target({ TYPE_USE }) is what the null 
annotations are actually required to have in this case, and since TYPE_USE is 
new in Java 1.8, that certainly complicates this request.

Original comment by [email protected] on 3 Jan 2014 at 5:13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant