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

Java中.this和.class的含义

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

Java中.this和.class的含义

这个

Home.this
引用
Home
该类的当前实例。

此表达式的正式术语似乎是qualified
this,如Java语言规范的15.8.4节所引用。

在一个简单的类中,说

Home.this
this
将等效。此表达式仅在存在内部类且需要引用封闭类的情况下使用。

例如:

class Hello {  class World {    public void doSomething() {      Hello.this.doAnotherThing();      // Here, "this" alone would refer to the instance of      // the World class, so one needs to specify that the      // instance of the Hello class is what is being      // referred to.    }  }  public void doAnotherThing() {  }}

家庭类

Home.class
Home
类的表示形式作为
Class
对象返回。

此表达式的正式术语是类文字,如Java语言规范的15.8.2节所引用。

在大多数情况下,此表达式在使用反射时使用,并且需要一种方法来引用类本身而不是类的实例。



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

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

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