As everybody knows (or should know) the following is useless:
[code=java]
private static int x= 42;
...
x= x++;
[/code]
The value of x will stay 42. Or does it? Have a look at the following little experiment
and try to figure out what is happening:
[code=java]
public class TrickyStuff {
private static int x= 42;
public static void main(String[] args) {
(new Thread() {
public void run() {
while(x == 42);
System.out.prin tln( "x != 42" );
System.exit(0);
}
} ).start();
System.out.prin tln("x= "+x);
while(true) { x=x++;}
}
}[/code]
kind regards,
Jos
[code=java]
private static int x= 42;
...
x= x++;
[/code]
The value of x will stay 42. Or does it? Have a look at the following little experiment
and try to figure out what is happening:
[code=java]
public class TrickyStuff {
private static int x= 42;
public static void main(String[] args) {
(new Thread() {
public void run() {
while(x == 42);
System.out.prin tln( "x != 42" );
System.exit(0);
}
} ).start();
System.out.prin tln("x= "+x);
while(true) { x=x++;}
}
}[/code]
kind regards,
Jos
Comment