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

# 6.5.5. Meaning of Type Names

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

## 6.5.5.1. Simple Type Names

If a type name consists of a single *Identifier*, then the identifier must occur in the scope of exactly one declaration of a class, interface, or type parameter with this name ([§6.3](6.3.md)), or a compile-time error occurs.

If the declaration denotes a type parameter of a generic class or interface C ([§8.1.2](8.1.2.md), [§9.1.2](9.1.2.md)), then both of the following must be true, or a compile-time error occurs:

- The type name does not occur in a static context ([§8.1.3](8.1.3.md)).
- If the type name appears in a nested class or interface declaration of C, then the immediately enclosing class or interface declaration of the type name is an inner class of C.

For example, the type name must not appear in the body of a `static` method declared by C, nor in the body of an instance method of a `static` class nested within C.

If the declaration denotes a type parameter of a generic method or constructor `m` ([§8.4.4](8.4.4.md), [§8.8.4](8.8.4.md)), and the type name appears directly or indirectly in the body of a local class, local interface, or anonymous class D declared directly in the body of `m`, then both of the following must be true, or a compile-time error occurs:

- The type name does not occur in a static context.
- D is an inner class, and the immediately enclosing class or interface declaration of the type name is D or an inner class of D.

For example, the type name must not appear in the body of a `static` method declared by D, nor (if D is a local interface) in the body of a default method of D.

The meaning of the type name is the in-scope class, interface, or type parameter.

**Example 6.5.5.1-1. References to Type Parameters**

```
class Box<T> {
    T val;
    Box(T t) { val = t; }

    static Box<T> empty() {  // compile-time error
        return new Box<>(null);
    }

    static <U> Box<U> make(U val) {
        interface Checker {
            void check(U val);  // compile-time error
        }

        class NullChecker implements Checker {
            public void check(U val) {
                if (val == null) {
                    throw new IllegalArgumentException();
                }
            }
        }

        new NullChecker().check(val);
        return new Box<U>(val);
    }
}
```

The class type parameter T is in scope throughout the declaration of class `Box`; however, using the name T in the declaration of `static` method `empty` is illegal.

Similarly, the method type parameter U is in scope throughout the declaration of method `make`; however, using the name U in the declaration of the (implicitly `static`) local interface `Checker` is illegal.

## 6.5.5.2. Qualified Type Names

If a type name is of the form `Q.Id`, then `Q` must be either the name of a class, interface, or type parameter in a package uniquely visible to the current module, or the name of a package uniquely visible to the current module ([§7.4.3](7.4.3.md)).

If `Id` names exactly one accessible class or interface ([§6.6](6.6.md)) that is a member of the class, interface, type parameter, or package denoted by `Q`, then the qualified type name denotes that class or interface.

If `Id` does not name a member class or interface within `Q` ([§8.5](8.5.md), [§9.5](9.5.md)), or the member class or interface named `Id` within `Q` is not accessible, or `Id` names more than one member class or interface within `Q`, then a compile-time error occurs.

**Example 6.5.5.2-1. Qualified Type Names**

```
class Test {
    public static void main(String[] args) {
        java.util.Date date =
            new java.util.Date(System.currentTimeMillis());
        System.out.println(date.toLocaleString());
    }
}
```

This program produced the following output the first time it was run:

```
Sun Jan 21 22:56:29 1996
```

In this example, the name `java.util.Date` must denote a type, so we first use the procedure recursively to determine if `java.util` is an accessible class or interface or type parameter, or a package, which it is, and then we look to see if the class `Date` is accessible in this package.
