누구든지이 프로그램의 출력을 설명 할 수 있습니까? 왜 두 번째 가치가 7입니까? 재귀 함수 호출을 go(this)
자바 재귀 함수 트릭
public class ThisIsTricky {
int state = 0;
public ThisIsTricky(int s) {
state = s;
}
public static void main(String[] args) {
ThisIsTricky obj1 = new ThisIsTricky(1);
ThisIsTricky obj2 = new ThisIsTricky(2);
System.out.println(obj1.go(obj1) + "" + obj2.go(obj2));
}
int go(ThisIsTricky thisIsTricky) {
if (this.state == 2) {
thisIsTricky.state = 5;
go(this);
}
return ++this.state;
}
}
출력을 이해하기
수 없습니다 : -
2 7
올바른 해석 – Ironluca