Static initializer and the Singleton pattern
Weiqi Gao
weiqigao@networkusa.net
Tue Dec 4 21:16:00 GMT 2001
Bryce McKinlay wrote:
> 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().
Is gcj correct in doing it?
--
Weiqi Gao
weiqigao@networkusa.net
More information about the Java
mailing list