6.5.1 Syntactic Classification of a Name According to Context
A name is syntactically classified as a PackageName in these contexts:
- In a package declaration (§7.4)
- In a type-import-on-demand declaration (§7.5.2)
- To the left of the "
.
" in a qualified PackageName
- To the left of the "
.
" in a qualified TypeName
A name is syntactically classified as a TypeName in these contexts:
- In a single-type-import declaration (§7.5.1)
- In an
extends
clause in a class declaration (§8.1.3)
- In an
implements
clause in a class declaration (§8.1.4)
- In an
extends
clause in an interface declaration (§9.1.3)
- As a Type (or the part of a Type that remains after all brackets are deleted) in any of the following contexts:
- In a field declaration (§8.3, §9.3)
- As the result type of a method (§8.4, §9.4)
- As the type of a formal parameter of a method or constructor (§8.4.1, §8.6.1, §9.4)
- As the type of an exception that can be thrown by a method or constructor (§8.4.4, §8.6.4, §9.4)
- As the type of a local variable (§14.3)
- As the type of an exception parameter in a
catch
clause of a try
statement (§14.18)
- As the class type of an instance that is to be created in a class instance creation expression (§15.8)
- As the element type of an array to be created in an array creation expression (§15.9)
- As the type mentioned in the cast operator of a cast expression (§15.15)
- As the type that follows the
instanceof
relational operator (§15.19.2)
A name is syntactically classified as an ExpressionName in these contexts:
- As the array reference expression in an array access expression (§15.12)
- As a PostfixExpression (§15.13)
- As the left-hand operand of an assignment operator (§15.25)
A name is syntactically classified as a MethodName in this context:
· Before the "(
" in a method invocation expression (§15.11)
A name is syntactically classified as an AmbiguousName in these contexts:
- To the left of the "
.
" in a qualified ExpressionName
- To the left of the "
.
" in a qualified MethodName
- To the left of the "
.
" in a qualified AmbiguousName