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.

EXPRESSIONS Constant Expression 15.28<br />

operand then assigns 4 to k, calculates the value 6 for k+2, and then multiplies<br />

4 by 6 to get 24. This is added to the saved value 1 to get 25, which is then stored<br />

into k by the += operator. An identical analysis applies to the case that uses a[0].<br />

In short, the statements<br />

k += (k = 4) * (k + 2);<br />

a[0] += (a[0] = 4) * (a[0] + 2);<br />

behave in exactly the same manner as the statements:<br />

k = k + (k = 4) * (k + 2);<br />

a[0] = a[0] + (a[0] = 4) * (a[0] + 2);<br />

15.27 Expression<br />

An Expression is any assignment expression:<br />

Expression:<br />

AssignmentExpression<br />

Unlike C and C++, the <strong>Java</strong> programming language has no comma operator.<br />

15.28 Constant Expression<br />

. . . the old and intent expression was a constant, not an occasional, thing . . .<br />

A Tale of Two Cities<br />

ConstantExpression:<br />

Expression<br />

A compile-time constant expression is an expression denoting a value of<br />

primitive type or a String that does not complete abruptly and is composed<br />

using only the following:<br />

• Literals of primitive type and literals of type String (§3.10.5)<br />

• Casts to primitive types and casts to type String<br />

DRAFT<br />

• <strong>The</strong> unary operators +, -, ~, and ! (but not ++ or --)<br />

• <strong>The</strong> multiplicative operators *, /, and %<br />

• <strong>The</strong> additive operators + and -<br />

• <strong>The</strong> shift operators , and >>><br />

• <strong>The</strong> relational operators = (but not instanceof)<br />

525

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

Saved successfully!

Ooh no, something went wrong!