🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16533

Re: Java Bug or tough certification exam question for you concerning static initializers

#16533
From: Wido Riezebos
Date: Wed, 10 Feb 1999 00:00
40 lines
1816 bytes
Thanks Tor! You passed the test!
The following illustrates the problem even better if you understand what is
going on:

class  A
{
  static String str = new String("init: ");
  static { str += "a";
         }
}

class  B extends A
{ static String str2 = new String("xx");
  static { str += "b";
         }
}

public class Test
{ public static void main(String[] args)
{ //  System.out.println(B.str2);
    System.out.println(B.str);
  }
}

The first (preceded by //) forces class B to be loaded, firing the static
initializer of B
You would think any reference to B would do this, but that obviously is not
the case.

Nevertheless it seems that the java performance bunch forgot about the
static initializers when they implemented an optimizing feature like this!
It scares the hell out of me: What about new versions of the VM?
I havent read the language spec completely but I fear that nothing is said
about this all since it is a compiler feature: optimizing code, forgetting
about static initializers. (I think this is the only scenario; using static
initializers; where such an optimization causes problems)

'Guess I stumbled into one of the dark corners of Java here..

Wido
Technical Details
Message-ID: <79rv1c$bc62@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <79rmjc$99p15@forums.borland.com> <u3e4eijhw.fsf@sds.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,1512ce46783b168a
X-Google-Attributes: gidf74b3,public
From: "Wido Riezebos" <[REMOVE_THIS]w.riezebos@itude.com>
Subject: Re: Java Bug or tough certification exam question for you concerning static initializers
Date: 1999/02/10
Message-ID: <79rv1c$bc62@forums.borland.com>
X-Deja-AN: 442786415
References: <79rmjc$99p15@forums.borland.com> <u3e4eijhw.fsf@sds.no>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language