---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 17 Edition"
java_version: 17
chapter: "Chapter 6. Names"
section: "6.5.1"
heading: "6.5.1. Syntactic Classification of a Name According to Context"
parent: "6.5. Determining the Meaning of a Name"
source: https://docs.oracle.com/javase/specs/jls/se17/html/jls-6.html#jls-6.5.1
id: "6.5.1"
url: https://jvm.obfuscated.software/jls/se17/6.5.1.html
raw: https://jvm.obfuscated.software/jls/se17/6.5.1.md
---

# 6.5.1. Syntactic Classification of a Name According to Context

A name is syntactically classified as a *ModuleName* in these contexts:

- In a `requires` directive in a module declaration ([§7.7.1](7.7.1.md))
- To the right of `to` in an `exports` or `opens` directive in a module declaration ([§7.7.2](7.7.2.md))

A name is syntactically classified as a *PackageName* in these contexts:

- To the right of `exports` or `opens` in a module declaration
- To the left of the "`.`" in a qualified *PackageName*

A name is syntactically classified as a *TypeName* in these contexts:

- To name a class or interface:

  1. In a `uses` or `provides` directive in a module declaration ([§7.7.1](7.7.1.md))
  2. In a single-type-import declaration ([§7.5.1](7.5.1.md))
  3. To the left of the `.` in a single-static-import declaration ([§7.5.3](7.5.3.md))
  4. To the left of the `.` in a static-import-on-demand declaration ([§7.5.4](7.5.4.md))
  5. In a `permits` clause of a `sealed` class or interface declaration ([§8.1.6](8.1.6.md), [§9.1.4](9.1.4.md)).
  6. To the left of the `(` in a constructor declaration ([§8.8](8.8.md))
  7. After the `@` sign in an annotation ([§9.7](9.7.md))
  8. To the left of `.class` in a class literal ([§15.8.2](15.8.2.md))
  9. To the left of `.this` in a qualified `this` expression ([§15.8.4](15.8.4.md))
  10. To the left of `.super` in a qualified superclass field access expression ([§15.11.2](15.11.2.md))
  11. To the left of `.`*Identifier* or `.super.`*Identifier* in a qualified method invocation expression ([§15.12](15.12.md))
  12. To the left of `.super::` in a method reference expression ([§15.13](15.13.md))

- As the *Identifier* or dotted *Identifier* sequence that constitutes any *ReferenceType* (including a *ReferenceType* to the left of the brackets in an array type, or to the left of the < in a parameterized type, or in a non-wildcard type argument of a parameterized type, or in an `extends` or `super` clause of a wildcard type argument of a parameterized type) in the 17 contexts where types are used ([§4.11](4.11.md)):

  1. In an `extends` or `implements` clause of a class declaration ([§8.1.4](8.1.4.md), [§8.1.5](8.1.5.md))
  2. In an `extends` clause of an interface declaration ([§9.1.3](9.1.3.md))
  3. The return type of a method ([§8.4.5](8.4.5.md), [§9.4](9.4.md)), including the type of an element of an annotation interface ([§9.6.1](9.6.1.md))
  4. In the `throws` clause of a method or constructor ([§8.4.6](8.4.6.md), [§8.8.5](8.8.5.md), [§9.4](9.4.md))
  5. In an `extends` clause of a type parameter declaration of a generic class, interface, method, or constructor ([§8.1.2](8.1.2.md), [§9.1.2](9.1.2.md), [§8.4.4](8.4.4.md), [§8.8.4](8.8.4.md))
  6. The type in a field declaration of a class or interface ([§8.3](8.3.md), [§9.3](9.3.md))
  7. The type in a formal parameter declaration of a method, constructor, or lambda expression ([§8.4.1](8.4.1.md), [§8.8.1](8.8.1.md), [§9.4](9.4.md), [§15.27.1](15.27.1.md))
  8. The type of the receiver parameter of a method ([§8.4](8.4.md))
  9. The type in a local variable declaration in either a statement ([§14.4.2](14.4.2.md), [§14.14.1](14.14.1.md), [§14.14.2](14.14.2.md), [§14.20.3](14.20.3.md)) or a pattern ([§14.30.1](14.30.1.md))
  10. A type in an exception parameter declaration ([§14.20](14.20.md))
  11. The type in a record component declaration of a record class ([§8.10.1](8.10.1.md))
  12. In an explicit type argument list to an explicit constructor invocation statement or class instance creation expression or method invocation expression ([§8.8.7.1](8.8.7.1.md), [§15.9](15.9.md), [§15.12](15.12.md))
  13. In an unqualified class instance creation expression, either as the class type to be instantiated ([§15.9](15.9.md)) or as the direct superclass or direct superinterface of an anonymous class to be instantiated ([§15.9.5](15.9.5.md))
  14. The element type in an array creation expression ([§15.10.1](15.10.1.md))
  15. The type in the cast operator of a cast expression ([§15.16](15.16.md))
  16. The type that follows the `instanceof` relational operator ([§15.20.2](15.20.2.md))
  17. In a method reference expression ([§15.13](15.13.md)), as the reference type to search for a member method or as the class type or array type to construct.

The extraction of a *TypeName* from the identifiers of a *ReferenceType* in the 16 contexts above is intended to apply recursively to all sub-terms of the *ReferenceType*, such as its element type and any type arguments.

For example, suppose a field declaration uses the type `p.q.Foo[]`. The brackets of the array type are ignored, and the term `p.q.Foo` is extracted as a dotted sequence of *Identifiers* to the left of the brackets in an array type, and classified as a *TypeName*. A later step determines which of `p`, `q`, and `Foo` is a type name or a package name.

As another example, suppose a cast operator uses the type `p.q.Foo<? extends String>`. The term `p.q.Foo` is again extracted as a dotted sequence of *Identifier* terms, this time to the left of the `<` in a parameterized type, and classified as a *TypeName*. The term `String` is extracted as an *Identifier* in an `extends` clause of a wildcard type argument of a parameterized type, and classified as a *TypeName*.

A name is syntactically classified as an *ExpressionName* in these contexts:

- As the qualifying expression in a qualified superclass constructor invocation ([§8.8.7.1](8.8.7.1.md))
- As the qualifying expression in a qualified class instance creation expression ([§15.9](15.9.md))
- As the array reference expression in an array access expression ([§15.10.3](15.10.3.md))
- As a *PostfixExpression* ([§15.14](15.14.md))
- As the left-hand operand of an assignment operator ([§15.26](15.26.md))
- As a *VariableAccess* in a `try`-with-resources statement ([§14.20.3](14.20.3.md))

A name is syntactically classified as a *MethodName* in this context:

- Before the "`(`" in a method invocation expression ([§15.12](15.12.md))

A name is syntactically classified as a *PackageOrTypeName* in these contexts:

- To the left of the "`.`" in a qualified *TypeName*
- In a type-import-on-demand declaration ([§7.5.2](7.5.2.md))

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 rightmost `.` that occurs before the "`(`" in a method invocation expression
- To the left of the "`.`" in a qualified *AmbiguousName*
- In the default value clause of an annotation element declaration ([§9.6.2](9.6.2.md))
- To the right of an "`=`" in an an element-value pair ([§9.7.1](9.7.1.md))
- To the left of `::` in a method reference expression ([§15.13](15.13.md))

The effect of syntactic classification is to restrict certain kinds of entities to certain parts of expressions:

- The name of a field, parameter, or local variable may be used as an expression ([§15.14.1](15.14.1.md)).
- The name of a method may appear in an expression only as part of a method invocation expression ([§15.12](15.12.md)).
- The name of a class or interface may appear in an expression only as part of a class literal ([§15.8.2](15.8.2.md)), a qualified `this` expression ([§15.8.4](15.8.4.md)), a class instance creation expression ([§15.9](15.9.md)), an array creation expression ([§15.10.1](15.10.1.md)), a cast expression ([§15.16](15.16.md)), an `instanceof` expression ([§15.20.2](15.20.2.md)), an enum constant ([§8.9](8.9.md)), or as part of a qualified name for a field or method.
- The name of a package may appear in an expression only as part of a qualified name for a class or interface.
