[英]Java language spec: “an invocation of Class” as return type of method in annotation type
The Java 8 Language Spec says in the discussion of annotation type elements : Java 8语言规范在注释类型元素的讨论中说:
The return type of a method declared in an annotation type must be one of the following, or a compile-time error occurs: 在注释类型中声明的方法的返回类型必须是以下之一,否则会发生编译时错误:
... Class or an invocation of Class (§4.5) ......类或类的调用(§4.5)
What is meant with "an invocation of Class"? “课程的召唤”是什么意思? Just something like Class<Number>
, or more than that? 就像Class<Number>
东西,还是更多呢?
Yes, that's exactly that. 是的,就是这样。 The terminology is confusing, rarely used, and I can't seem to find it anywhere in the JSL. 术语很混乱,很少使用,我似乎无法在JSL的任何地方找到它。 It is in a tutorial , though: 不过,它在教程中 :
To reference the generic
Box
class from within your code, you must perform a generic type invocation, which replacesT
with some concrete value, such as Integer: 要从代码中引用通用Box
类,必须执行泛型类型调用,它将T
替换为某些具体值,例如Integer:Box<Integer> integerBox;
You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument —
Integer
in this case — to theBox
class itself. 您可以将泛型类型调用视为与普通方法调用类似,但不是将参数传递给方法,而是将类型参数(在本例中为Integer
传递给Box
类本身。Type Parameter and Type Argument Terminology: Many developers use the terms "type parameter" and "type argument" interchangeably, but these terms are not the same. 类型参数和类型参数术语:许多开发人员可以互换地使用术语“类型参数”和“类型参数”,但这些术语并不相同。 When coding, one provides type arguments in order to create a parameterized type. 编码时,提供类型参数以创建参数化类型。 Therefore, the
T
inFoo<T>
is a type parameter and the String inFoo<String> f
is a type argument. 因此,T
在Foo<T>
是一种类型的参数,并且在字符串Foo<String> f
是类型参数。 This lesson observes this definition when using these terms. 本课程在使用这些术语时会遵循此定义。Like any other variable declaration, this code does not actually create a new
Box
object. 与任何其他变量声明一样,此代码实际上不会创建新的Box
对象。 It simply declares thatintegerBox
will hold a reference to a "Box
ofInteger
", which is howBox<Integer>
is read. 它只是声明integerBox
将保存对“Box
ofInteger
”的引用,这就是Box<Integer>
的读取方式。An invocation of a generic type is generally known as a parameterized type. 泛型类型的调用通常称为参数化类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.