Java的作用域结构不能与类型用途注释 [英] Java scoping construct cannot be annotated with type-use
问题描述
我要与批注 @Nullable
-annotation一个完全合格的类名(从Java框架检查),例如:
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?
推荐答案
的 Java语言规范(草案第8版)§8.3指定一个UnannClassType为
The Java language specification (draft for version 8) §8.3 specifies a "UnannClassType" as
UnannClassType:
标识符[TypeArguments]
UnannClassOrInterfaceType。 {}注释标识符[TypeArguments]
UnannClassType:
Identifier [TypeArguments]
UnannClassOrInterfaceType . {Annotation} Identifier [TypeArguments]
因此,你需要声明:
Thus, you need the declaration:
private transient org.apache.lucene.search.@Nullable Query cached_results;
或者在检查框架的增强Java 7的编译器:
Or in the augmented java 7 compiler of the checker framework:
private transient org.apache.lucene.search./*@Nullable*/ Query cached_results;
的注:普通的Java编译器忽略 / * @ *可空/
的
这篇关于Java的作用域结构不能与类型用途注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!