Java scoping construct cannot be annotated with type-use

后端 未结 1 1746
广开言路
广开言路 2021-02-20 01:05

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

class Demo {
    private transien         


        
1条回答
  •  一整个雨季
    2021-02-20 01:28

    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*/.

    0 讨论(0)
提交回复
热议问题