The items of the target_info union (except for the first) specify precisely which type in a declaration or expression is annotated. The first item specifies not which type, but rather which declaration of a type parameter is annotated. The items are as follows:
-
The
type_parameter_targetitem indicates that an annotation appears on the declaration of the i'th type parameter of a generic class, generic interface, generic method, or generic constructor.type_parameter_target { u1 type_parameter_index; }The value of the
type_parameter_indexitem specifies which type parameter declaration is annotated. Atype_parameter_indexvalue of0specifies the first type parameter declaration. -
The
supertype_targetitem indicates that an annotation appears on a type in theextendsorimplementsclause of a class or interface declaration.supertype_target { u2 supertype_index; }A
supertype_indexvalue of 65535 specifies that the annotation appears on the superclass in anextendsclause of a class declaration.Any other
supertype_indexvalue is an index into theinterfacesarray of the enclosingClassFilestructure, and specifies that the annotation appears on that superinterface in either theimplementsclause of a class declaration or theextendsclause of an interface declaration. -
The
type_parameter_bound_targetitem indicates that an annotation appears on the i'th bound of the j'th type parameter declaration of a generic class, interface, method, or constructor.type_parameter_bound_target { u1 type_parameter_index; u1 bound_index; }The value of the of
type_parameter_indexitem specifies which type parameter declaration has an annotated bound. Atype_parameter_indexvalue of0specifies the first type parameter declaration.The value of the
bound_indexitem specifies which bound of the type parameter declaration indicated bytype_parameter_indexis annotated. Abound_indexvalue of0specifies the first bound of a type parameter declaration.The
type_parameter_bound_targetitem records that a bound is annotated, but does not record the type which constitutes the bound. The type may be found by inspecting the class signature or method signature stored in the appropriateSignatureattribute. -
The
empty_targetitem indicates that an annotation appears on either the type in a field declaration, the type in a record component declaration, the return type of a method, the type of a newly constructed object, or the receiver type of a method or constructor.empty_target { }Only one type appears in each of these locations, so there is no per-type information to represent in the
target_infounion. -
The
formal_parameter_targetitem indicates that an annotation appears on the type in a formal parameter declaration of a method, constructor, or lambda expression.formal_parameter_target { u1 formal_parameter_index; }The value of the
formal_parameter_indexitem specifies which formal parameter declaration has an annotated type. Aformal_parameter_indexvalue of i may, but is not required to, correspond to the i'th parameter descriptor in the method descriptor (§4.3.3).The
formal_parameter_targetitem records that a formal parameter's type is annotated, but does not record the type itself. The type may be found by inspecting the method descriptor, although aformal_parameter_indexvalue of0does not always indicate the first parameter descriptor in the method descriptor; see the note in §4.7.18 for a similar situation involving theparameter_annotationstable. -
The
throws_targetitem indicates that an annotation appears on the i'th type in thethrowsclause of a method or constructor declaration.throws_target { u2 throws_type_index; }The value of the
throws_type_indexitem is an index into theexception_index_tablearray of theExceptionsattribute of themethod_infostructure enclosing theRuntimeVisibleTypeAnnotationsattribute. -
The
localvar_targetitem indicates that an annotation appears on the type in a local variable declaration, including a variable declared as a resource in atry-with-resources statement.localvar_target { u2 table_length; { u2 start_pc; u2 length; u2 index; } table[table_length]; }The value of the
table_lengthitem gives the number of entries in thetablearray. Each entry indicates a range ofcodearray offsets within which a local variable has a value. It also indicates the index into the local variable array of the current frame at which that local variable can be found. Each entry contains the following three items:-
start_pc, length
The given local variable has a value at indices into the
codearray in the interval [start_pc,start_pc + length), that is, betweenstart_pcinclusive andstart_pc + lengthexclusive. -
index
The given local variable must be at
indexin the local variable array of the current frame.If the local variable at
indexis of typedoubleorlong, it occupies bothindexandindex + 1.
A table is needed to fully specify the local variable whose type is annotated, because a single local variable may be represented with different local variable indices over multiple live ranges. The
start_pc,length, andindexitems in each table entry specify the same information as aLocalVariableTableattribute.The
localvar_targetitem records that a local variable's type is annotated, but does not record the type itself. The type may be found by inspecting the appropriateLocalVariableTableattribute. -
-
The
catch_targetitem indicates that an annotation appears on the i'th type in an exception parameter declaration.catch_target { u2 exception_table_index; }The value of the
exception_table_indexitem is an index into theexception_tablearray of theCodeattribute enclosing theRuntimeVisibleTypeAnnotationsattribute.The possibility of more than one type in an exception parameter declaration arises from the multi-
catchclause of thetrystatement, where the type of the exception parameter is a union of types (JLS §14.20). A compiler usually creates oneexception_tableentry for each type in the union, which allows thecatch_targetitem to distinguish them. This preserves the correspondence between a type and its annotations. -
The
offset_targetitem indicates that an annotation appears on either the type in an instanceof expression or a new expression, or the type before the::in a method reference expression.offset_target { u2 offset; }The value of the
offsetitem specifies thecodearray offset of either the bytecode instruction corresponding to the instanceof expression, the new bytecode instruction corresponding to the new expression, or the bytecode instruction corresponding to the method reference expression. -
The
type_argument_targetitem indicates that an annotation appears either on the i'th type in a cast expression, or on the i'th type argument in the explicit type argument list for any of the following: a new expression, an explicit constructor invocation statement, a method invocation expression, or a method reference expression.type_argument_target { u2 offset; u1 type_argument_index; }The value of the
offsetitem specifies thecodearray offset of either the bytecode instruction corresponding to the cast expression, the new bytecode instruction corresponding to the new expression, the bytecode instruction corresponding to the explicit constructor invocation statement, the bytecode instruction corresponding to the method invocation expression, or the bytecode instruction corresponding to the method reference expression.For a cast expression, the value of the
type_argument_indexitem specifies which type in the cast operator is annotated. Atype_argument_indexvalue of0specifies the first (or only) type in the cast operator.The possibility of more than one type in a cast expression arises from a cast to an intersection type.
For an explicit type argument list, the value of the
type_argument_indexitem specifies which type argument is annotated. Atype_argument_indexvalue of0specifies the first type argument.