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.

EXECUTION Detailed Initialization Procedure 12.4.2<br />

Thus, the test program:<br />

interface I {<br />

int i = 1, ii = Test.out("ii", 2);<br />

}<br />

interface J extends I {<br />

int j = Test.out("j", 3), jj = Test.out("jj", 4);<br />

}<br />

interface K extends J {<br />

int k = Test.out("k", 5);<br />

}<br />

class Test {<br />

public static void main(String[] args) {<br />

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

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

}<br />

static int out(String s, int i) {<br />

System.out.println(s + "=" + i);<br />

return i;<br />

}<br />

}<br />

produces the output:<br />

1<br />

j=3<br />

jj=4<br />

3<br />

<strong>The</strong> reference to J.i is to a field that is a compile-time constant; therefore, it<br />

does not cause I to be initialized. <strong>The</strong> reference to K.j is a reference to a field<br />

actually declared in interface J that is not a compile-time constant; this causes initialization<br />

of the fields of interface J, but not those of its superinterface I, nor<br />

those of interface K. Despite the fact that the name K is used to refer to field j of<br />

interface J, interface K is not initialized.<br />

DRAFT<br />

12.4.2 Detailed Initialization Procedure<br />

Because the <strong>Java</strong> programming language is multithreaded, initialization of a class<br />

or interface requires careful synchronization, since some other thread may be trying<br />

to initialize the same class or interface at the same time. <strong>The</strong>re is also the possibility<br />

that initialization of a class or interface may be requested recursively as<br />

part of the initialization of that class or interface; for example, a variable initializer<br />

in class A might invoke a method of an unrelated class B, which might in turn<br />

319

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

Saved successfully!

Ooh no, something went wrong!