このケースではAを返すと思ったのですが、まだ空のままです。どうしてでしょうか?多分add の奴を自分は間違って理解していると思うのですが。
java
1public class RecursiveApp { 2// data field 3String top; 4RecursiveApp rest; 5 public static void main (String [] args){ 6 RecursiveApp t0 = new RecursiveApp();// 空 7 t0.add("A"); 8 System.out.println(t0.toString()); 9/** 10return new RecursiveApp(block, this); 11so RecursiveApp("A", this) 12このケースではt0 のtop がAになり t0のrest がt0になるのでしょうか? 13*/ 14 15 16 17 18 19 20} 21// empty RecursiveApp 22// 1 constructor 23public RecursiveApp(){ 24 this.top = " "; 25 this.rest = null; 26 27 28} 29// 2 constructor 30private RecursiveApp(String top, RecursiveApp rest){ 31 this.top = top; 32 this.rest = rest; 33} 34// ここがいまいちわかりません。 35public RecursiveApp add(String block){ 36 return new RecursiveApp(block, this);// 2 constructor 37} 38 39public String toString(){ 40 return this.top; 41 42} 43 44 45 46 47 48}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。