英文:
Why is the element type here annotated as Integer and not Integer[]?
问题
让我们假设@TypeAnno
是某种类型注释。
@TypeAnno Integer[] vec;
在这里,元素类型Integer
被注释,而不是Integer[]
。为什么呢?
英文:
Let's say that @TypeAnno
is some type annotation.
@TypeAnno Integer[] vec;
Here the element type Integer
is annotated and not Integer[]
. Why?
答案1
得分: 2
Integer[]
是一个复合类型,由两部分组成:[]
是数组部分,Integer
是元素类型。希望能够在每个部分上都写上类型注解。
@Nullable Object @NonNull []
是一个非空数组,其中的对象可能为空。
更多信息,请参阅类型注解常见问题解答条目:
数组注解(例如 @NonNull Object @Nullable [])的含义是什么?
以及
我不喜欢数组和接收器注解。。
此外,还可以参阅类型注解规范中的 数组注解语法 部分。这也在Java语言规范中有所涉及(例如,注解可能出现的位置 部分)。
英文:
A type annotation applies to the immediately following type component.
Integer[]
is a compond type that consists of two parts: []
is the array part and Integer
is the element type. It is desirable to be able to write a type annotation on each of the parts.
@Nullable Object @NonNull []
is a non-null array of possibly-null objects.
For more information,
See the Type Annotations FAQ entries
What is the meaning of array annotations such as @NonNull Object @Nullable []? and I don't like array and receiver annotations.. Also
see section Syntax of array annotations in the type annotation specifiaction. This is also addressed in the Java Language Specification (for example, section Where Annotations May Appear).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论