---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 15 Edition"
java_version: 15
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/se15/html/jls-15.html#jls-15.9.1
id: "15.9.1"
url: https://jvm.obfuscated.software/jls/se15/15.9.1.html
raw: https://jvm.obfuscated.software/jls/se15/15.9.1.md
---

# 15.9.1. Determining the Class being Instantiated

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

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

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, then:

  The *Identifier* in *ClassOrInterfaceTypeToInstantiate* must denote either a class that is accessible, non-`final`, and not an enum type, or an interface that is accessible ([§6.6](6.6.md)). Otherwise a compile-time error occurs.

  If the *Identifier* in *ClassOrInterfaceTypeToInstantiate* denotes a class, C, then an anonymous direct subclass of C is declared. If *TypeArguments* is present, then C has type arguments given by *TypeArguments*; if `<>` is present, then C will have its type arguments inferred in [§15.9.3](15.9.3.md); otherwise, C has no type arguments. 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 *Identifier* in *ClassOrInterfaceTypeToInstantiate* denotes an interface, I, then an anonymous direct subclass of `Object` that implements I is declared. If *TypeArguments* is present, then I has type arguments given by *TypeArguments*; if `<>` is present, then I will have its type arguments inferred in [§15.9.3](15.9.3.md); otherwise, I has no type arguments. 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, then:

  The *Identifier* in *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.

  Let the *Identifier* in *ClassOrInterfaceTypeToInstantiate* denote a class, C. An anonymous direct subclass of C is declared. If *TypeArguments* is present, then C has type arguments given by *TypeArguments*; if `<>` is present, then C will have its type arguments inferred in [§15.9.3](15.9.3.md); otherwise, C has no type arguments. 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, then:

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

  The class being instantiated is specified by the *Identifier* in *ClassOrInterfaceTypeToInstantiate*. If *TypeArguments* is present, then the class has type arguments given by *TypeArguments*; if `<>` is present, then the class will have its type arguments inferred in [§15.9.3](15.9.3.md); otherwise, the class has no type arguments.

- If the class instance creation expression is qualified, then:

  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*.

  The class being instantiated is specified by the *Identifier* in *ClassOrInterfaceTypeToInstantiate*. If *TypeArguments* is present, then the class has type arguments given by *TypeArguments*; if `<>` is present, then the class will have its type arguments inferred in [§15.9.3](15.9.3.md); otherwise, the class has no type arguments.
