This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Static initializer and the Singleton pattern


Weiqi Gao wrote:

>The following bit of code was distilled from a bigger application that
>exhibited a case of interference between the singleton pattern and
>static initializers.  Contrary to the naive expectation, under Sun's JDK
>this program prints 'false'.  And a check against the JVM spec confirms
>that the behavior is the expected bahavior.
>
>class Main {
>    public static void main(String[] args) {
>        System.out.println(A.getInstance() == B.a);
>    }
>}
>

Hmm... the problem is that GCJ is calling the static initializer for B 
from Main.main() before it calls A.getInstance().

regards

Bryce.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]