在Java中,this.method()和method()有什么区别? [英] In Java, what is the difference between this.method() and method()?

查看:199
本文介绍了在Java中,this.method()和method()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用 this.method()方法()(包括性能差异)之间有什么区别吗?

Is there any difference between calling this.method() and method() (including performance difference)?

推荐答案

唯一重要的是你使用 OuterClass.this.method()例如

The only time it matters is if you are using OuterClass.this.method() e.g.

class OuterClass {
    void method() { }

    class InnerClass {
        void method() {
            OuterClass.this.method(); // not the same as method().
        }
    }
 }

这篇关于在Java中,this.method()和method()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆