码迷,mamicode.com
首页 > 编程语言 > 详细

javac之向前引用

时间:2017-11-02 13:17:49      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:static   bsp   return   oid   style   rgs   enc   obj   ref   

 

可以参考JLS7:https://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3

public class Test5 {
	
	int a = m1();

	public int m1() {
		System.out.println(i);  // 0
		return i;
	}

	int b = (new Object() {
		public int t() {
			System.out.println(i); // 0
			return i;
		}
	}).t();
	
	{
		i = 100;
		System.out.println(this.i); // 100 
		//i = i+1; // error Cannot reference a field before it is defined
		//System.out.println(i); // error Cannot reference a field before it is defined
	}
	
	//int k = i+1; // error  Cannot reference a field before it is defined

	int i = 2;

	public static void main(String[] args) {
		Test5 t = new Test5();
		System.out.println(t.i); // 2
	}

}

 

javac之向前引用

标签:static   bsp   return   oid   style   rgs   enc   obj   ref   

原文地址:http://www.cnblogs.com/extjs4/p/7771573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!