public class Backhand {
int state = 0;
Backhand(int s) {
state = s;
}
public static void main(String... hi) {
Backhand b1 = new Backhand(1);
Backhand b2 = new Backhand(2);
System.out.println( b2.go(b2));
}
int go(Backhand b) {
if(this.state ==2) {
b.state = 5;
go(this);
}
return ++this.state;
}
}
当它运行时,它输出 7。我认为 ++this.state;
应该在方法 go 中只执行一次,输出应该是 6。有人可以解释这里发生了什么吗?