加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

方法的选择

发布时间:2020-12-12 13:32:09 所属栏目:百科 来源:网络整理
导读:? ? ? 解读JLS:https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.3 If the compile-time declaration is? void ,then the method invocation must be a top level expression (that is,the? Expression ?in an expression stateme

?

?

?

解读JLS:https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.3

If the compile-time declaration is?void,then the method invocation must be a top level expression (that is,the?Expression?in an expression statement (§14.8) or in the?ForInit?or?ForUpdate?part of a?for?statement (§14.14)),or a compile-time error occurs.

?

class T1 {
	public void a(){}
	public void b(){}
	public void test(int i){
		for(a();i<0;i++,b()){
			
		}
	}
}

?

?

解读JLS:https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.4.2

When accessing an instance variable,?super?means the same as a cast of?this?(§15.11.2),but this equivalence does not hold true for method invocation. This is demonstrated by the example:

class T1 {
	int a = 1;
}

class T2 extends T1 {
	int a = 2;
}

class T3 extends T2 {
	public void test() {
		System.out.println(((T1) this).a);
		System.out.println(((T2) this).a);
	}
}

public class TestB {
	public static void main(String[] args) {
		T3 t3 = new T3();
		t3.test();
	}
}

打印的结果为1、2  

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读