Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android中finish()和this.finish()的区别_Java_Android - Fatal编程技术网

Java android中finish()和this.finish()的区别

Java android中finish()和this.finish()的区别,java,android,Java,Android,在onPause()或onStop()方法中提供finish()和this.finish()是相同的。请熟悉这个的含义。->它的值是对当前对象的引用。例如,如果您有一个名为Foo的类,并且它有一个名为method()的方法,那么中的此将是对Foo的实例的引用(即:一个Foo对象)。通常您不需要使用thisfinish(),而this.finish()是相同的 对于问题的另一部分,请。此在任何上下文中都指包含的类。因此,如果您在活动中使用该方法,那么this.finish()与finish()相同

onPause()
onStop()
方法中提供
finish()
this.finish()
是相同的。请熟悉
这个的含义。
->它的值是对当前对象的引用。例如,如果您有一个名为
Foo
的类,并且它有一个名为
method()
的方法,那么
中的
将是对
Foo
的实例的引用(即:一个
Foo
对象)。通常您不需要使用
this

finish()
,而
this.finish()
是相同的


对于问题的另一部分,请。

在任何上下文中都指包含的类。因此,如果您在
活动中使用该方法,那么
this.finish()
finish()相同。
但是,如果您在不同的类类型中使用
this
,您可能没有
this.finish()
,在您的情况下也是一样的。有时使用此->很重要。。。如果有一个成员和一个方法参数同名,如以下示例所示:

    class foo{

    int number;

    void setNumber(int number);

    }
所以你可以用你的方法写

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

所以很清楚你使用了哪种元素。但是要小心,不要用相同的名字,这不是很好

尽管这个问题已经问了3年了,我还是更愿意对现在和未来的研究人员说几句话

只是一个对象引用。您不必每次都使用
,只需从子类实例获取父类的引用即可

让我们考虑使用<代码>线程< /COD>类.< /P>时的示例。

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.
    }
}

上面列出的,有不同用法,<>代码>这个< /Cord>关键字。最好在这里引用Oracle的文档

OP询问java,而不是C++。哦,对不起,你是对的。我在C++中写了我的例子-对不起