栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Java中使用关键字“ this”

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Java中使用关键字“ this”

this
关键字是对当前对象的引用。

class Foo{    private int bar;    public Foo(int bar)    {        // the "this" keyword allows you to specify that        // you mean "this type" and reference the members        // of this type - in this instance it is allowing        // you to disambiguate between the private member        // "bar" and the parameter "bar" passed into the        // constructor        this.bar = bar;    }}

另一种思考方式是

this
关键字就像你用来引用自己的人称代词。对于相同的概念,其他语言使用不同的词。VB使用Me和Python约定(因为Python不使用关键字,只是每个方法的隐式参数)将被使用
self

如果要引用本质上属于你的对象,你将说出以下内容:

我的手臂或我的腿

认为this这是一种类型说“我的”的方式。因此,伪代码表示将如下所示:

class Foo{    private int bar;    public Foo(int bar)    {        my.bar = bar;    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/456488.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号