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

# 15.9. Class Instance Creation Expressions

A class instance creation expression is used to create new objects that are instances of classes.

```
ClassInstanceCreationExpression:
  UnqualifiedClassInstanceCreationExpression
  ExpressionName . UnqualifiedClassInstanceCreationExpression
  Primary . UnqualifiedClassInstanceCreationExpression

UnqualifiedClassInstanceCreationExpression:
  new [TypeArguments] ClassOrInterfaceTypeToInstantiate ( [ArgumentList] ) [ClassBody]

ClassOrInterfaceTypeToInstantiate:
  {Annotation} Identifier {. {Annotation} Identifier} [TypeArgumentsOrDiamond]

TypeArgumentsOrDiamond:
  TypeArguments
  <>
```

The following production from [§15.12](15.12.md) is shown here for convenience:

```
ArgumentList:
  Expression {, Expression}
```

A class instance creation expression specifies a class to be instantiated, possibly followed by type arguments ([§4.5.1](4.5.1.md)) or a *diamond* (`<>`) if the class being instantiated is generic ([§8.1.2](8.1.2.md)), followed by (a possibly empty) list of actual value arguments to the constructor.

If the type argument list to the class is empty — the diamond form `<>` — the type arguments of the class are inferred. It is legal, though strongly discouraged as a matter of style, to have white space between the "`<`" and "`>`" of a diamond.

If the constructor is generic ([§8.8.4](8.8.4.md)), the type arguments to the constructor may similarly either be inferred or passed explicitly. If passed explicitly, the type arguments to the constructor immediately follow the keyword `new`.

It is a compile-time error if a class instance creation expression provides type arguments to a constructor but uses the diamond form for type arguments to the class.

This rule is introduced because inference of a generic class's type arguments may influence the constraints on a generic constructor's type arguments.

If *TypeArguments* is present immediately after `new`, or immediately before `(`, then it is a compile-time error if any of the type arguments are wildcards ([§4.5.1](4.5.1.md)).

The exception types that a class instance creation expression can throw are specified in [§11.2.1](11.2.1.md).

Class instance creation expressions have two forms:

- *Unqualified class instance creation expressions* begin with the keyword `new`.

  An unqualified class instance creation expression may be used to create an instance of a class, regardless of whether the class is a top level ([§7.6](7.6.md)), member ([§8.5](8.5.md), [§9.5](9.5.md)), local ([§14.3](14.3.md)), or anonymous class ([§15.9.5](15.9.5.md)).

- *Qualified class instance creation expressions* begin with a *Primary* expression or an *ExpressionName*.

  A qualified class instance creation expression enables the creation of instances of inner member classes and their anonymous subclasses.

Both unqualified and qualified class instance creation expressions may optionally end with a class body. Such a class instance creation expression declares an *anonymous class* ([§15.9.5](15.9.5.md)) and creates an instance of it.

A class instance creation expression is a poly expression ([§15.2](15.2.md)) if it uses the diamond form for type arguments to the class, and it appears in an assignment context or an invocation context ([§5.2](5.2.md), [§5.3](5.3.md)). Otherwise, it is a standalone expression.

We say that a class is *instantiated* when an instance of the class is created by a class instance creation expression. Class instantiation involves determining the class to be instantiated ([§15.9.1](15.9.1.md)), the enclosing instances (if any) of the newly created instance ([§15.9.2](15.9.2.md)), and the constructor to be invoked to create the new instance ([§15.9.3](15.9.3.md)).

**Sections:**

- [15.9.1. Determining the Class being Instantiated](15.9.1.md)
- [15.9.2. Determining Enclosing Instances](15.9.2.md)
- [15.9.3. Choosing the Constructor and its Arguments](15.9.3.md)
- [15.9.4. Run-Time Evaluation of Class Instance Creation Expressions](15.9.4.md)
- [15.9.5. Anonymous Class Declarations](15.9.5.md)
