System.out.println( a [ (a = b)[3] ] );
首先,a
评估 的值 ( {1, 2, 3, 4}
)。接下来,a = b
被执行;这将 的值分配b
给a
并返回的值b
。b[3] = { 2, 3, 1, 0 }
是0
,所以,最终,。{1,2,3,4}[b[3]] = {1,2,3,4}[0] = 1
要看到这一点,请考虑以下事项:
public static void main(String[] args) throws FileNotFoundException {
int[] a = { 1, 2, 3, 4 };
System.out.println( a() [ (a = b())[c()] ] );
}
public static int[] a() {
System.out.println('a');
return new int[]{ 1, 2, 3, 4 };
}
public static int[] b() {
System.out.println('b');
return new int[]{ 2, 3, 1, 0 };
}
public static int c() {
System.out.println('c');
return 3;
}
输出:
a
b
c
1