The Java 8 Language Spec says in the discussion of 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)
What is meant with "an invocation of Class"? Just something like Class<Number>
, or more than that?
Yes, that's exactly that. The terminology is confusing, rarely used, and I can't seem to find it anywhere in the 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<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With