java中class的含义_.this和.class在java中的含义

首页

Home.this指的是Home类的当前实例。

此表达式的正式术语似乎是Qualified this,如Java语言规范的第15.8.4节中所述。

在一个简单的类,说Home.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将返回Home类的表示作为Class对象。

此表达式的正式术语是class literal,如Java语言规范的第15.8.2节中所述。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值