方法的选择

 

 

 

解读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  

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...