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.

15.2 Variables as Values EXPRESSIONS<br />

410<br />

declared void (§8.4). Such an expression can be used only as an expression statement<br />

(§14.8), because every other context in which an expression can appear<br />

requires the expression to denote something. An expression statement that is a<br />

method invocation may also invoke a method that produces a result; in this case<br />

the value returned by the method is quietly discarded.<br />

Value set conversion (§5.1.13) is applied to the result of every expression that<br />

produces a value.<br />

Each expression occurs in either:<br />

• <strong>The</strong> declaration of some (class or interface) type that is being declared: in a<br />

field initializer, in a static initializer, in an instance initializer, in a constructor<br />

declaration, in an annotation, or in the code for a method.<br />

• An annotation of a package or of a top-level type declaration .<br />

15.2 Variables as Values<br />

If an expression denotes a variable, and a value is required for use in further evaluation,<br />

then the value of that variable is used. In this context, if the expression<br />

denotes a variable or a value, we may speak simply of the value of the expression.<br />

If the value of a variable of type float or double is used in this manner, then<br />

value set conversion (§5.1.13) is applied to the value of the variable.<br />

15.3 Type of an Expression<br />

If an expression denotes a variable or a value, then the expression has a type<br />

known at compile time. <strong>The</strong> rules for determining the type of an expression are<br />

explained separately below for each kind of expression.<br />

<strong>The</strong> value of an expression is assignment compatible (§5.2) with the type of<br />

the expression, unless heap pollution (§4.12.2.1) occurs. Likewise the value stored<br />

in a variable is always compatible with the type of the variable, unless heap pollution<br />

occurs. In other words, the value of an expression whose type is T is always<br />

suitable for assignment to a variable of type T.<br />

Note that an expression whose type is a class type F that is declared final is<br />

guaranteed to have a value that is either a null reference or an object whose class<br />

is F itself, because final types have no subclasses.<br />

DRAFT

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

Saved successfully!

Ooh no, something went wrong!