下面的代码应该不会在Windows 7 x86 jdk 7上引发AssertionError(每个JLS example for volatile带有-ea开启)? public class TestVolatile {
static volatile int i = 0;
static volatile int j = 0;
static void one() {
i++;
考虑下面的类: class Foo {
public volatile int number;
public int method1() {
int ret = number = 1;
return ret;
}
public int method2() {
int ret = number = 2;
return
通过JLS 8.3.2.3时,我无法理解下面的代码。 class Z {
static { i = j + 2; }
static int i, j;
static { j = 4; }
}
的代码导致错误Cannot reference a field before it is defined 但如果我更改代码以 class Z {
static { i = 2; }
stati
为什么它失败,出现如下所示的错误?我不确定在JLS的哪个地方去寻找这样的限制。 public class A {
static A foo() {
return null;
}
public static void main(String[] args) {
A A = A.foo();
}
}
错误在编译时 A.java: