为什么这里将元素类型注释为Integer而不是Integer[]?

huangapple go评论72阅读模式
英文:

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).

huangapple
  • 本文由 发表于 2020年8月30日 02:13:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63650307.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定