increment - Java Initialize Variable Incremented -
is risky initialize global variable increment of global variable?
example:
int a=0; int b=a++; int c=a++; int d=a++;
this should output:
0,1,2,3
could happen compiler read global value before other?
it behave expected. if try use field before it's defined, compiler throw error:
public class foo { int = b++; //compiler error here int b = 0; }
this covered in jls 8.3
for case, output of variables if they're not modified, be:
a = 3 b = 0 c = 1 d = 2
Comments
Post a Comment