So, I was reading through the chapter on class initialization (to try
and either fix bernd's static initializer problem or say "it's working
according to spec, the jdk is busted.") and I've come across one
example that gives the expected output on japhar and doesn't on the
JDK.
----
interface I {
int i = 1, ii = StaticInit4.out("ii", 2);
}
interface J extends I {
int j = StaticInit4.out("j", 3), jj = StaticInit4.out("jj", 4);
}
interface K extends J {
int k = StaticInit4.out("k", 5);
}
class StaticInit4 {
public static void main(String[] args) {
System.out.println(J.i);
System.out.println(K.j);
}
public static int out(String s, int i) {
System.out.println(s + "=" + i);
return i;
}
}
----
The expected output (and what japhar produces) is:
1
j=3
jj=4
3
The JDK, however, outputs:
1
ii=2
j=3
jj=4
3
What I'd like to know is if this test works on any version of the JDK
(i'm using 1.1.5 here). I'm hoping they've fixed the bug in their
runtime and aren't going to rewrite the spec to get around it.
Chris