this的用法(class.this)

来源:互联网 发布:光盘复制软件 编辑:程序博客网 时间:2024/05/16 08:38

引子:今天看了一些android发现一个东西

java1

public class SimpleService extends Service{public class SimpleBinder extends Binder{SimpleService getsService(){return SimpleService.this;}}}

java2

activity.this.oncreat();

就以上两种情况分析了一下


其中myplay是对  类名.this

       myplay2是对  类名.this.属性分析

其中都是  类名.this.属性 的时候, 是对内部类和外部类的分析



这里做了一下 ,总结个人理解 ,this可以看做,直属类的实例化,也就是当前代码所属的类的实例化


你在外部实例化之后

不就是 So so=new  So();

so.play();

在类内的一个方法中调用就是:

this.play();

而类名.this.方法;

也是 .this等于实例化。

慢慢理解 this是指向自己的指针


0 0
原创粉丝点击