think in java笔记:this关键字
来源:互联网 发布:rimworld mac下载 编辑:程序博客网 时间:2024/05/16 18:44
think in java笔记:this关键字
The this keyword—which can be used only inside a
non-static method—produces the reference to the object that the method has been called
for. You can treat the reference just like any other object reference. Keep in mind that if
you’re calling a method of your class from within another method of your class, you don’t
need to use this . You simply call the method. The current this reference is automatically
used for the other method.
The this keyword is also useful for passing the current object to another method
译:
This关键字,只可以用在非静态方法中,指向当前方法所属的对象。你可以把这个对象引用当作正常的对象来对待,但是你要记住,如果在一个方法中需要调用另外一个此对象的方法,不需要加this,可以直接调用方法。当前对象的引用会自动应用到方法上。
同时this关键字也是很有用的,在调用其它方法是,将本身对象当作参数传入进去。
还有一种用法,是在构造函数中调用构造函数时,会用到this。
ps:
- 构造函数使用this的时候,只能在第一行调用,并且只能调用一次
- 调用构造函数只能是构造函数,其他函数不可以
- think in java笔记:this关键字
- [Think in Java 笔记] Final关键字
- think in java 笔记(一) final关键字
- Think in java 笔记
- think in java 笔记
- Think in java笔记
- think in java 笔记
- Think in java 笔记
- Think In Java 笔记
- Think in Java 笔记
- Think in Java笔记
- this key -- think in java notes
- Think in java笔记一则
- think in java 学习笔记
- Think In java 笔记一
- think in java笔记 upcasting
- Think in java笔记 final
- Think in java笔记: Annotation
- JavaScript tips
- PHP实现文件上传的例子(附详细源码)
- 支持setOnItemClickListener的RecyclerView
- 上帝造题的七分钟 [Tyvj 1716]
- BASISI系统中如何配置web service
- think in java笔记:this关键字
- 获取当前url地址和目录不包含访问的文件名
- 最左原位
- ehcache.xml配置文件详解
- listview.setselection(position)不起作用
- Android网络相关(WiFi的开关,WiFi热点的开关,获取手机IP地址等)
- Java多线程-- 基本概念
- nmake(vs2015)命令行编译libjpeg-turbo(x86/amd64)
- 测试流程