-2

提供finish()と方法this.finish()は同じですかonPause()onStop()

4

5 に答える 5

3

はい。の意味をよく理解してくださいthis.-> その値は現在のオブジェクトへの参照です。たとえば、 という名前のクラスがあり、 という名前Fooのメソッドがある場合、method()そのthis中に のインスタンスFoo(つまり、Fooオブジェクト) への参照があります。通常は使用する必要はありませんthis

于 2012-10-22T07:49:34.243 に答える
2

質問は3歳ですが、現在および将来の研究者に光を当てることを好みます.

thisは単なるオブジェクト参照ですthis。子クラスのインスタンスから親クラスの参照を取得する必要がある場合を除いて、毎回使用する必要はありません。

Threadクラスを使用する場合の例を考えてみましょう。

public class A
{
   public A()
    {
        new Thread(new Runnable()
         {
             public void start()
             {
                  B child=new B(A.this);//In this scenario,'A.this' refers to the parent class 'A' in which the 'Thread' class instantiated.If you simply pass 'this' ,then it would refer to the 'Thread' class as this statement executed in the current scope.
             }
         }).start();
    }
}
public class B
{
A parent;
    public B(A parent)
    {
        this.parent=parent;//'this' refers to the class B ,so that it can access the global variable 'parent' ,then assigns it with the local variable 'parent' passed through the constructor.
    }
}

上記のように、キーワードにはさまざまな使用法があります。thisここでオラクルのドキュメントを参照することをお勧めしますhttps://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

于 2015-12-07T13:19:08.720 に答える
2

thisどのコンテキストでも、含まれているクラスを指します。したがって、 内でメソッドを使用している場合Activitythis.finish()と同じですが、別のクラス タイプでfinish().使用している場合は、thisthis.finish()

于 2012-10-22T07:52:07.080 に答える
0

あなたの場合は同じです。次の例のように、同じ名前のメンバーとメソッド パラメーターがある場合は、this->... を使用することが重要な場合があります。

    class foo{

    int number;

    void setNumber(int number);

    }

だからあなたはあなたの方法で書くことができます

    void foo::setNumber(int number)
    {
    this->number = number; 
    }

したがって、どの要素を使用したかは明らかです。ただし、同じ名前を使用しないように注意してください。あまり良くありません。

于 2012-10-22T08:01:00.447 に答える
0

finish()this.finish()同じです。

質問の他の部分については、アクティビティのライフサイクルについてお読みください。

于 2012-10-22T07:50:49.783 に答える