---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 8 Edition"
java_version: 8
chapter: "Chapter 15. Expressions"
section: "15.9.1"
heading: "15.9.1. Determining the Class being Instantiated"
parent: "15.9. Class Instance Creation Expressions"
source: https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.9.1
id: "15.9.1"
url: https://jvm.obfuscated.software/jls/se8/15.9.1.html
raw: https://jvm.obfuscated.software/jls/se8/15.9.1.md
---

# 15.9.1. Determining the Class being Instantiated

If the class instance creation expression ends in a class body, then the class being instantiated is an anonymous class. Then:

- If the class instance creation expression is unqualified:

  The *ClassOrInterfaceTypeToInstantiate* must denote a class that is accessible, non-`final`, and not an enum type; or denote an interface that is accessible. Otherwise a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with `<>`, then a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with *TypeArguments*, then *ClassOrInterfaceTypeToInstantiate* must denote a well-formed parameterized type ([§4.5](4.5.md)), or a compile-time error occurs.

  Let T be the type denoted by *ClassOrInterfaceTypeToInstantiate*. If T denotes a class, then an anonymous direct subclass of T is declared. If T denotes an interface, then an anonymous direct subclass of `Object` that implements T is declared. In either case, the body of the subclass is the *ClassBody* given in the class instance creation expression.

  The class being instantiated is the anonymous subclass.

- If the class instance creation expression is qualified:

  The *ClassOrInterfaceTypeToInstantiate* must unambiguously denote an inner class that is accessible, non-`final`, not an enum type, and a member of the compile-time type of the *Primary* expression or the *ExpressionName*. Otherwise, a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with `<>`, then a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with *TypeArguments*, then *ClassOrInterfaceTypeToInstantiate* must denote a well-formed parameterized type, or a compile-time error occurs.

  Let T be the type denoted by *ClassOrInterfaceTypeToInstantiate*. An anonymous direct subclass of T is declared. The body of the subclass is the *ClassBody* given in the class instance creation expression.

  The class being instantiated is the anonymous subclass.

If a class instance creation expression does not declare an anonymous class, then:

- If the class instance creation expression is unqualified:

  The *ClassOrInterfaceTypeToInstantiate* must denote a class that is accessible, non-`abstract`, and not an enum type. Otherwise, a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with `<>`, but the class denoted by *ClassOrInterfaceTypeToInstantiate* is not generic, then a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with *TypeArguments*, then *ClassOrInterfaceTypeToInstantiate* must denote a well-formed parameterized class, or a compile-time error occurs.

  The class being instantiated is the class denoted by *ClassOrInterfaceTypeToInstantiate*.

- If the class instance creation expression is qualified:

  The *ClassOrInterfaceTypeToInstantiate* must unambiguously denote an inner class that is accessible, non-`abstract`, not an enum type, and a member of the compile-time type of the *Primary* expression or the *ExpressionName*.

  If *ClassOrInterfaceTypeToInstantiate* ends with `<>`, and the class denoted by *ClassOrInterfaceTypeToInstantiate* is not generic, then a compile-time error occurs.

  If *ClassOrInterfaceTypeToInstantiate* ends with *TypeArguments*, then *ClassOrInterfaceTypeToInstantiate* must denote a well-formed parameterized class, or a compile-time error occurs.

  The class being instantiated is the class denoted by *ClassOrInterfaceTypeToInstantiate*.
