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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

EXPRESSIONS Simple Assignment Operator = 15.26.1<br />

◆ First, the left-hand operand is evaluated to produce a variable. If this evaluation<br />

completes abruptly, then the assignment expression completes abruptly<br />

for the same reason; the right-hand operand is not evaluated and no assignment<br />

occurs.<br />

◆ Otherwise, the right-hand operand is evaluated. If this evaluation completes<br />

abruptly, then the assignment expression completes abruptly for the same<br />

reason and no assignment occurs.<br />

Otherwise, the value of the right-hand operand is converted to the type of the<br />

left-hand variable, is subjected to value set conversion (§5.1.13) to the appropriate<br />

standard value set (not an extended-exponent value set), and the result of the conversion<br />

is stored into the variable.<strong>The</strong> rules for assignment to an array component<br />

are illustrated by the following example program:<br />

class ArrayReferenceThrow extends RuntimeException { }<br />

class IndexThrow extends RuntimeException { }<br />

class RightHandSideThrow extends RuntimeException { }<br />

class IllustrateSimpleArrayAssignment {<br />

static Object[] objects = { new Object(), new Object() };<br />

static Thread[] threads = { new Thread(), new Thread() };<br />

static Object[] arrayThrow() {<br />

throw new ArrayReferenceThrow();<br />

}<br />

static int indexThrow() { throw new IndexThrow(); }<br />

static Thread rightThrow() {<br />

throw new RightHandSideThrow();<br />

}<br />

static String name(Object q) {<br />

String sq = q.getClass().getName();<br />

int k = sq.lastIndexOf('.');<br />

return (k < 0) ? sq : sq.substring(k+1);<br />

}<br />

static void testFour(Object[] x, int j, Object y) {<br />

String sx = x == null ? "null" : name(x[0]) + "s";<br />

String sy = name(y);<br />

System.out.println();<br />

try {<br />

System.out.print(sx + "[throw]=throw => ");<br />

x[indexThrow()] = rightThrow();<br />

System.out.println("Okay!");<br />

} catch (Throwable e) { System.out.println(name(e)); }<br />

DRAFT<br />

515

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

Saved successfully!

Ooh no, something went wrong!