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 Compound Assignment Operators 15.26.2<br />

class RightHandSideThrow extends RuntimeException { }<br />

class IllustrateCompoundArrayAssignment {<br />

static String[] strings = { "Simon", "Garfunkel" };<br />

static double[] doubles = { Math.E, Math.PI };<br />

static String[] stringsThrow() {<br />

throw new ArrayReferenceThrow();<br />

}<br />

static double[] doublesThrow() {<br />

throw new ArrayReferenceThrow();<br />

}<br />

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

static String stringThrow() {<br />

throw new RightHandSideThrow();<br />

}<br />

static double doubleThrow() {<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 testEight(String[] x, double[] z, int j) {<br />

String sx = (x == null) ? "null" : "Strings";<br />

String sz = (z == null) ? "null" : "doubles";<br />

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

try {<br />

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

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

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

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

try {<br />

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

z[indexThrow()] += doubleThrow();<br />

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

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

try {<br />

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

x[indexThrow()] += "heh";<br />

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

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

try {<br />

DRAFT<br />

521

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

Saved successfully!

Ooh no, something went wrong!