Buttonのコンストラクタの挙動がよくわかりません。
Sample2.javaに
public class Sample2 extends Activity { public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); LinearLayout tt = new LinearLayout(this); tt.setOrientation(LinearLayout.VERTICAL); setContentView(tt); TextView tv = new TextView(this); tv.setText("いらっしゃいませ。"); Button bt = new Button(this); bt.setText("購入"); tt.addView(tv); tt.addView(bt); } }
とコードを書きました。この
Button bt = new Button(this);
の
new Button(this);
のコンストラクタの挙動がよくわかりません。
Buttonコンストラクタは
package android.widget; import android.content.Context; import android.util.AttributeSet; import android.widget.TextView; import android.widget.RemoteViews.RemoteView; @RemoteView public class Button extends TextView { public Button(Context context) { super((Context)null, (AttributeSet)null, 0, 0); throw new RuntimeException("Stub!"); } public Button(Context context, AttributeSet attrs) { super((Context)null, (AttributeSet)null, 0, 0); throw new RuntimeException("Stub!"); } public Button(Context context, AttributeSet attrs, int defStyleAttr) { super((Context)null, (AttributeSet)null, 0, 0); throw new RuntimeException("Stub!"); } public Button(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super((Context)null, (AttributeSet)null, 0, 0); throw new RuntimeException("Stub!"); } public CharSequence getAccessibilityClassName() { throw new RuntimeException("Stub!"); } }
というコードなのですが、
この5つのButtonメソッドの全部を通っていることがわかりました(ブレークポイントを置いたら)。なのに、Buttonのコンストラクタはthisの引数1つしか持っていないので、なぜ、引数を複数もつButtonメソッドも通るのかわかりません。なぜ、5つのButtonメソッドの全部を通るのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。