Topic: 问题 (evaluation order)

  Print this page

1.问题 (evaluation order) Copy to clipboard
Posted by: xiaopan
Posted on: 2003-03-18 15:17

int[] a = {4,4};
int b =1;
a[b] = b =0;
结果数组a 为什么植,为什么?

2.Re:问题 [Re: xiaopan] Copy to clipboard
Posted by: snowbug
Posted on: 2003-03-18 23:16

It's a very good question. It has something to do with the expression evaluation order of the JVM. According to the JVM specification, the order of the evaluation is from the left to the right, so the line:
a[b] = b = 0;
evaluates to:
a[1] = (b = 0);

so the array will be: {4, 0}.

3.Re:问题 [Re: snowbug] Copy to clipboard
Posted by: mitnickcbc
Posted on: 2003-03-18 23:45

snowbug wrote:
It's a very good question. It has something to do with the expression evaluation order of the JVM. According to the JVM specification, the order of the evaluation is from the left to the right, so the line:
a = b = 0;
evaluates to:
a[1] = (b = 0);

so the array will be: {4, 0}.


I tested it, you are right.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923