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