10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8.8.4 Generic Constructors CLASSES<br />

242<br />

8.8.4 Generic Constructors<br />

It is possible for a constructor to be declared generic, independently of whether<br />

the class the constructor is declared in is itself generic. A constructor is generic if<br />

it declares one or more type variables (§4.4). <strong>The</strong>se type variables are known as<br />

the formal type parameters of the constructor. <strong>The</strong> form of the formal type parameter<br />

list is identical to a type parameter list of a generic class or interface, as<br />

described in §8.1.2.<br />

<strong>The</strong> scope of a constructor’s type parameter is the entire declaration of the<br />

constructor, including the type parameter section itself. <strong>The</strong>refore, type parameters<br />

can appear as parts of their own bounds, or as bounds of other type parameters<br />

declared in the same section.<br />

Type parameters of generic constructor need not be provided explicitly when<br />

a generic constructor is invoked. When they are not provided, they are inferred as<br />

specified in §15.12.2.7.<br />

8.8.5 Constructor Throws<br />

<strong>The</strong> throws clause for a constructor is identical in structure and behavior to the<br />

throws clause for a method (§8.4.6).<br />

8.8.6 <strong>The</strong> Type of a Constructor<br />

<strong>The</strong> type of a constructor consists of its signature and the exception types given its<br />

throws clause.<br />

8.8.7 Constructor Body<br />

DRAFT<br />

<strong>The</strong> first statement of a constructor body may be an explicit invocation of another<br />

constructor of the same class or of the direct superclass (§8.8.7.1).<br />

ConstructorBody:<br />

{ ExplicitConstructorInvocationopt BlockStatementsopt }<br />

It is a compile-time error for a constructor to directly or indirectly invoke<br />

itself through a series of one or more explicit constructor invocations involving<br />

this. If the constructor is a constructor for an enum type (§8.9), it is a compiletime<br />

error for it to invoke the superclass constructor explicitly.<br />

If a constructor body does not begin with an explicit constructor invocation<br />

and the constructor being declared is not part of the primordial class Object, then<br />

the constructor body is implicitly assumed by the compiler to begin with a super-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!