这个this能用什么代替,还有这个this什么能代替,什么不
aide吧
全部回复
仅看楼主
level 9
这个this能用什么代替[疑问],还有这个this什么能代替,什么不能代替,他到底有啥用[疑问]
2018年07月28日 07点07分 1
level 13
this代表当前实例
2018年07月28日 08点07分 3
能详细解释一下吗
2018年07月28日 08点07分
level 13
比如
class Test {
@Override
public boolean equals(Object o) {
return this == o;
}
}
然后
Test test = new Test();
test.equals(test); //返回true
在外面对于Test的实例就是刚刚new出来的对象,Test这个类里想获得自己就写this
2018年07月28日 08点07分 4
**大哥,虽然我还是不懂[泪]
2018年07月28日 08点07分
level 13
类似于self,去学学java基础吧
2018年07月28日 08点07分 5
level 13
this就是当前类自己。
比如 a=new A()
this就相当于a这个变量
2018年07月28日 09点07分 6
ActivityA.this为啥能省略为this
2018年07月28日 09点07分
@积极具有层次感 行为在方法里面,默认就是ActivityA,所以可以省略, 如果你在点击事件里面,就不能省略,
2018年07月28日 09点07分
@积极具有层次感 this代表当前类,如果在点击事件里面this就代表点击事件这个类,所以不能省略ActivityA.this
2018年07月28日 09点07分
666
2018年07月28日 13点07分
level 14
推荐把类名也写出来:
类名.this
2018年07月28日 10点07分 7
level 13
小明有一支笔,小红有一支笔,我有一支笔,this.笔相当于我的笔,同理还有小明.笔,小红.笔
2018年07月28日 10点07分 8
666
2018年07月28日 12点07分
level 12
this=当前类.this,要看传入的参数
2018年07月29日 04点07分 9
level 9
[滑稽]可以代替,赋值给变量
Context ctx=this;
2018年07月29日 09点07分 10
level 11
this指一个类型为当前类的一个对象
2018年07月29日 13点07分 11
level 9
[滑稽]看情况 能被替换
2018年07月30日 09点07分 12
level 11
this指当前对象,而super指父类对象
2018年08月02日 00点08分 13
1