Java Reference
In-Depth Information
System.out.println(s + "=" + i);
return i;
}
}
This program produces the output:
1
j=3
jj=4
3
The reference to J.i is to a field that is a constant variable (§ 4.12.4 ) ; therefore, it does
not cause I to be initialized (§ 13.4.9 ) .
The reference to K.j is a reference to a field actually declared in interface J that is not
a constant variable; this causes initialization of the fields of interface J , but not those
of its superinterface I , nor those of interface K .
Despite the fact that the name K is used to refer to field j of interface J , interface K is
not initialized.
12.4.2. Detailed Initialization Procedure
Because the Java programming language is multithreaded, initialization of a class or inter-
face requires careful synchronization, since some other thread may be trying to initialize
the same class or interface at the same time. There is also the possibility that initialization
of a class or interface may be requested recursively as part of the initialization of that class
or interface; for example, a variable initializer in class A might invoke a method of an un-
related class B , which might in turn invoke a method of class A . The implementation of the
Java Virtual Machine is responsible for taking care of synchronization and recursive ini-
tialization by using the following procedure.
The procedure assumes that the Class object has already been verified and prepared, and
that the Class object contains state that indicates one of four situations:
• This Class object is verified and prepared but not initialized.
• This Class object is being initialized by some particular thread T .
• This Class object is fully initialized and ready for use.
• This Class object is in an erroneous state, perhaps because initialization was at-
tempted and failed.
Search WWH ::




Custom Search