Java scope cannot be annotated using type

I want to annotate the full class name with @Nullable -nnation (from the Java Checker Framework), for example:

 class Demo { private transient @Nullable org.apache.lucene.search.Query cached_results; // ... } 

However, this leads to an error:

 scoping construct cannot be annotated with type-use annotation: @checkers.nullness.quals.Nullable 

How can I annotate fully qualified class names?

+8
java java-8 annotations checker-framework
source share
1 answer

Java Language Specification (draft for version 8) Β§8.3 indicates "UnannClassType" as

UnannClassType:
ID [TypeArguments]
UnannClassOrInterfaceType. {Annotation} ID [TypeArguments]

So you need an ad:

 private transient org.apache.lucene.search.@Nullable Query cached_results; 

Or in the java 7 augmented compiler of the check framework compiler:

 private transient org.apache.lucene.search./*@Nullable*/ Query cached_results; 

NOTE: regular Java compilers ignore /*@Nullable*/ .

+9
source share

All Articles