문제

I want to annotate a fully qualified class name with @Nullable-annotation (from the Java Checker Framework), e.g.:

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

    // ...
}

However this results in the error:

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

How can I annotate fully qualified class names?

도움이 되었습니까?

해결책

The Java language specification (draft for version 8) §8.3 specifies a "UnannClassType" as

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

Thus, you need the declaration:

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

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

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top