Java 语言规范:"an invocation of Class" 作为注释类型中的 return 类型的方法
Java language spec: "an invocation of Class" as return type of method in annotation type
Java 8 语言规范在 annotation type elements 的讨论中说:
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)
“调用 Class”是什么意思?就像 Class<Number>
一样,还是更多?
是的,就是这样。这个术语令人困惑,很少使用,而且我似乎无法在 JSL 的任何地方找到它。它在 a tutorial 中,但是:
To reference the generic Box
class from within your code, you must
perform a generic type invocation, which replaces T
with some concrete
value, such as 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
the Box
class itself.
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
in Foo<T>
is a type parameter and the String in
Foo<String> f
is a type argument. This lesson observes this definition
when using these terms.
Like any other variable declaration, this code does not actually
create a new Box
object. It simply declares that integerBox
will hold
a reference to a "Box
of Integer
", which is how Box<Integer>
is read.
An invocation of a generic type is generally known as a parameterized
type.
Java 8 语言规范在 annotation type elements 的讨论中说:
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)
“调用 Class”是什么意思?就像 Class<Number>
一样,还是更多?
是的,就是这样。这个术语令人困惑,很少使用,而且我似乎无法在 JSL 的任何地方找到它。它在 a tutorial 中,但是:
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<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.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. This lesson observes this definition when using these terms.Like any other variable declaration, this code does not actually create a new
Box
object. It simply declares thatintegerBox
will hold a reference to a "Box
ofInteger
", which is howBox<Integer>
is read.An invocation of a generic type is generally known as a parameterized type.