Wednesday 25 June 2014

Type Contexts

Type contexts: where annotations apply to types used in declarations and expressions.

There are 16 type contexts, all represented by the enum constant TYPE_USE
of java.lang.annotation.ElementType.

16 type contexts are

1. A type in the extends or implements clause of a class declaration

2. A type in the extends clause of an interface declaration

3. The return type of a method (including the type of an element of an
annotation type)

4. A type in the throws clause of a method or constructor

5. A type in the extends clause of a type parameter declaration of a generic
class, interface, method, or constructor

6. The type in a field declaration of a class or interface (including an enum
constant)

7. The type in a formal parameter declaration of a method, constructor, or
lambda expression

8. The type of the receiver parameter of a method

9. The type in a local variable declaration

10. The type in an exception parameter declaration

In expressions

1. A type in the explicit type argument list to an explicit constructor invocation
statement or class instance creation expression or method invocation expression

2. In an unqualified class instance creation expression, as the class type to be
instantiated or as the direct superclass or direct superinterface of an anonymous class to be instantiated.

3. The element type in an array creation expression

4. The type in the cast operator of a cast expression

5. The type that follows the instanceof relational operator

6. In a method reference expression , as the reference type to search for a member method or as the class type or array type to construct.







Prevoius                                                 Next                                                 Home

No comments:

Post a Comment