嗨,您能解决我对以下程序的疑问吗?输出为 2 7,但据我了解,这是 2,6,为什么 go 方法又调用了一个额外的时间,而 count 递增为 7。
class Handed {
int state = 0;
Handed(int s) {
state = s;
}
public static void main(String... hi) {
Handed b1 = new Handed(1);
Handed b2 = new Handed(2);
int t1 = b1.go(b1);
int t2 = b2.go(b2);
System.out.println(t1 + " " + t2);
//System.out.println(b1.go(b1) + " " + b2.go(b2));
}
int go(Handed b) {
if(this.state == 2) {
b.state = 5; go(this);
}
int t3 = ++this.state;
return t3;
}
}