Well, so if I use static initialization blocks to access another static data inside another class:
public class StaticTestA {
public static Queue queue = new LinkedList();
static {
System.out.println("A start");
StaticTestC.queue.add("A");
StaticTestA.queue.add("A");
StaticTestB.queue.add("A");
System.out.println("A stop");
}
}
public class StaticTestB {
public static Queue queue = new LinkedList();
static {
System.out.println("B start");
StaticTestC.queue.add("B");
StaticTestA.queue.add("B");
StaticTestB.queue.add("B");
System.out.println("B stop");
}
}
public class StaticTestC {
public static Queue queue = new LinkedList();
static {
System.out.println("C start");
StaticTestC.queue.add("C");
StaticTestA.queue.add("C");
StaticTestB.queue.add("C");
System.out.println("C stop");
}
}
Result:
A start
C start
B start
B stop
C stop
A stop
[C, B, A]
[B, C, A]
[C, B, A]
Woot! :icon_cool: This thing is seriously cool! Setting this kind of thing up for the same result in Delphi was a real pain. But instead of throwing an error, Java solved it by executing concurrently.
But does anybody know if this is official or not? I fear it can just fail on other JREs...:S