根据看书和看得文章,引出了一个关于"向前引用"的问题:

public class InstanceInitTest {

    static {
//    {
        a = 6;
        System.out.println(a);//Cannot reference a field before it is defined
        System.out.println(fun());
    }
    static int fun(){
        return a;
    }
    static int a = 9;
    public static void main(String[] args) {
        System.out.println(new InstanceInitTest().a);
    }
}

 

java向前引用

 

编译出现的错误:

java向前引用

目前还并没有理解,资料较少,很多人也并不知道这么深入细节的java语言规范的东西。等有空再回顾理解下。

关于前向引用的链接:

http://www.cnblogs.com/nokiaguy/p/3156357.html

http://www.cnblogs.com/iamzhoug37/p/4306304.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-12-18
  • 2022-12-23
  • 2021-11-22
  • 2021-07-22
猜你喜欢
  • 2021-12-13
  • 2022-12-23
  • 2021-10-21
  • 2021-11-14
  • 2022-01-12
  • 2021-08-28
  • 2022-12-23
相关资源
相似解决方案