Question

JLS, on section 9.6.1 (http://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html#jls-9.6.1) says the following.

"It is a compile-time error if the return type of a method declared in an annotation type is not one of the following: a primitive type, String, Class, any parameterized invocation of Class, an enum type (§8.9), an annotation type, or an array type (§10) whose element type is one of the preceding types."

What is "any parameterized invocation of Class"? Any example?

Was it helpful?

Solution

Starting with Java 5, java.lang.Class type is generic, meaning that it can have a type parameter. By parameterized invocation of Class the documentation means "Class<...> with any kind of type parameters". You can find an example of it in the same document, e.g. the "Example 9.6.1-2":

interface Formatter {}

// Designates a formatter to pretty-print the annotated class
@interface PrettyPrinter {
    Class<? extends Formatter> value();
//  ^^^^^^^^^^^^^^^^^^^^^^^^^^------------ Here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top