---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 8 Edition"
java_version: 8
chapter: "Chapter 6. Names"
section: "6.5.6"
heading: "6.5.6. Meaning of Expression Names"
parent: "6.5. Determining the Meaning of a Name"
source: https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.5.6
id: "6.5.6"
url: https://jvm.obfuscated.software/jls/se8/6.5.6.html
raw: https://jvm.obfuscated.software/jls/se8/6.5.6.md
---

# 6.5.6. Meaning of Expression Names

The meaning of a name classified as an *ExpressionName* is determined as follows.

## 6.5.6.1. Simple Expression Names

If an expression name consists of a single *Identifier*, then there must be exactly one declaration denoting either a local variable, parameter, or field visible ([§6.4.1](6.4.1.md)) at the point at which the *Identifier* occurs. Otherwise, a compile-time error occurs.

If the declaration denotes an instance variable ([§8.3](8.3.md)), the expression name must appear within the declaration of an instance method ([§8.4](8.4.md)), constructor ([§8.8](8.8.md)), instance initializer ([§8.6](8.6.md)), or instance variable initializer ([§8.3.2](8.3.2.md)). If the expression name appears within a `static` method ([§8.4.3.2](8.4.3.2.md)), static initializer ([§8.7](8.7.md)), or initializer for a `static` variable ([§8.3.2](8.3.2.md), [§12.4.2](12.4.2.md)), then a compile-time error occurs.

If the declaration declares a `final` variable which is definitely assigned before the simple expression, the meaning of the name is the value of that variable. Otherwise, the meaning of the expression name is the variable declared by the declaration.

If the expression name appears in an assignment context, invocation context, or casting context, then the type of the expression name is the declared type of the field, local variable, or parameter after capture conversion ([§5.1.10](5.1.10.md)).

Otherwise, the type of the expression name is the declared type of the field, local variable or parameter.

That is, if the expression name appears "on the right hand side", its type is subject to capture conversion. If the expression name is a variable that appears "on the left hand side", its type is not subject to capture conversion.

**Example 6.5.6.1-1. Simple Expression Names**

```
class Test {
    static int v;
    static final int f = 3;
    public static void main(String[] args) {
        int i;
        i = 1;
        v = 2;
        f = 33;  // compile-time error
        System.out.println(i + " " + v + " " + f);
    }
}
```

In this program, the names used as the left-hand-sides in the assignments to `i`, `v`, and `f` denote the local variable `i`, the field `v`, and the value of `f` (not the variable `f`, because `f` is a `final` variable). The example therefore produces an error at compile time because the last assignment does not have a variable as its left-hand side. If the erroneous assignment is removed, the modified code can be compiled and it will produce the output:

```
1 2 3
```

## 6.5.6.2. Qualified Expression Names

If an expression name is of the form `Q.Id`, then `Q` has already been classified as a package name, a type name, or an expression name.

If `Q` is a package name, then a compile-time error occurs.

If `Q` is a type name that names a class type ([§8 (*Classes*)](8.md)), then:

- If there is not exactly one accessible ([§6.6](6.6.md)) member of the class type that is a field named `Id`, then a compile-time error occurs.

- Otherwise, if the single accessible member field is not a class variable (that is, it is not declared `static`), then a compile-time error occurs.

- Otherwise, if the class variable is declared `final`, then `Q.Id` denotes the value of the class variable.

  The type of the expression `Q.Id` is the declared type of the class variable after capture conversion ([§5.1.10](5.1.10.md)).

  If `Q.Id` appears in a context that requires a variable and not a value, then a compile-time error occurs.

- Otherwise, `Q.Id` denotes the class variable.

  The type of the expression `Q.Id` is the declared type of the class variable after capture conversion ([§5.1.10](5.1.10.md)).

  Note that this clause covers the use of `enum` constants ([§8.9](8.9.md)), since these always have a corresponding `final` class variable.

If `Q` is a type name that names an interface type ([§9 (*Interfaces*)](9.md)), then:

- If there is not exactly one accessible ([§6.6](6.6.md)) member of the interface type that is a field named `Id`, then a compile-time error occurs.

- Otherwise, `Q.Id` denotes the value of the field.

  The type of the expression `Q.Id` is the declared type of the field after capture conversion ([§5.1.10](5.1.10.md)).

  If `Q.Id` appears in a context that requires a variable and not a value, then a compile-time error occurs.

If `Q` is an expression name, let T be the type of the expression `Q`:

- If T is not a reference type, a compile-time error occurs.

- If there is not exactly one accessible ([§6.6](6.6.md)) member of the type T that is a field named `Id`, then a compile-time error occurs.

- Otherwise, if this field is any of the following:

  - A field of an interface type
  - A `final` field of a class type (which may be either a class variable or an instance variable)
  - The `final` field `length` of an array type ([§10.7](10.7.md))

  then `Q.Id` denotes the value of the field, unless it appears in a context that requires a variable and the field is a definitely unassigned blank `final` field, in which case it yields a variable.

  The type of the expression `Q.Id` is the declared type of the field after capture conversion ([§5.1.10](5.1.10.md)).

  If `Q.Id` appears in a context that requires a variable and not a value, and the field denoted by `Q.Id` is definitely assigned, then a compile-time error occurs.

- Otherwise, `Q.Id` denotes a variable, the field `Id` of class T, which may be either a class variable or an instance variable.

  The type of the expression `Q.Id` is the type of the field member after capture conversion ([§5.1.10](5.1.10.md)).

**Example 6.5.6.2-1. Qualified Expression Names**

```
class Point {
    int x, y;
    static int nPoints;
}

class Test {
    public static void main(String[] args) {
        int i = 0;
        i.x++;        // compile-time error
        Point p = new Point();
        p.nPoints();  // compile-time error
    }
}
```

This program encounters two compile-time errors, because the `int` variable `i` has no members, and because `nPoints` is not a method of class `Point`.

**Example 6.5.6.2-2. Qualifying an Expression with a Type Name**

Note that expression names may be qualified by type names, but not by types in general. A consequence is that it is not possible to access a class variable through a parameterized type. For example, given the code:

```
class Foo<T> {
    public static int classVar = 42;
}
```

the following assignment is illegal:

```
Foo<String>.classVar = 91; // illegal
```

Instead, one writes:

```
Foo.classVar = 91;
```

This does not restrict the Java programming language in any meaningful way. Type parameters may not be used in the types of static variables, and so the type arguments of a parameterized type can never influence the type of a static variable. Therefore, no expressive power is lost. The type name `Foo` appears to be a raw type, but it is not; rather, it is the name of the non-generic type `Foo` whose static member is to be accessed ([§6.1](6.1.md)). Since there is no use of a raw type, there are no unchecked warnings.
