Java this 关键字返回当前类实例变量
来源:互联网 发布:补水保湿 知乎 编辑:程序博客网 时间:2024/05/02 01:22
The this keyword can be used to return current class instance.
We can return the this keyword as an statement from the method. In such case, return type of the method must be the class type (non-primitive). Let’s see the example:
package com.hotmail.henrytien;public class ThisReturn {public ThisReturn getThisReturn() { return this;}void msg() { System.out.println(" Hello Java");}public static void main(String[] args) { // TODO Auto-generated method stub new ThisReturn().getThisReturn().msg();}}
Let’s prove that this keyword refers to the current class instance variable. In this program, we are printing the reference variable and this, output of both variables are same.
package com.hotmail.henrytien;public class A5 {A5(){ System.out.println(this); //prints same reference ID }public static void main(String[] args) { A5 obj = new A5(); System.out.println(obj); //prints the reference ID }}
output:
com.hotmail.henrytien.A5@5d748654
com.hotmail.henrytien.A5@5d748654
0 0
- Java this 关键字返回当前类实例变量
- Java this 返回当前对象
- this关键字_static_ 实例变量和类变量的区别_静态的应用
- 实例变量/类变量与this
- Java之this关键字区分局部变量和成员变量
- Java学习:“this”的引用及类变量、实例变量和局部变量
- this.成员变量:当前类的变量,this.方法:当前运行类的方法!
- Java关键字 this (this.实例成员;this()),以及Android中内部类中的中的this(*.this,ClassName.this)
- Lesson_for_java_day09--继承、实例化、构造方法、覆盖、重载、this关键字、super关键字、全局变量和局部变量
- java面向对象--this关键字、引用变量、构造方法
- 返回当前实例对象
- $this关键字是用来访问当前对象中的对象属性和对象方法的系统变量
- this关键字、static变量{理解}
- Java this关键字,static关键字
- JAVA this 当前对象
- java 类与对象 2---this关键字
- java类和对象之this关键字
- java 关键字this
- CListCtrl用法简介和使用技巧
- 如何去除tabBar的上横线和navigationBar的下横线
- 数组指针和指针数组
- android toolbar应用
- 记录一个map-site.xml -Xmx 1000m 写成了 1000报错问题
- Java this 关键字返回当前类实例变量
- 用VB进行十五个字母的排序——>编程
- winform DataGridView 自适应列宽
- 两个很实用很方便的函数核心及用法{(lower_bound)+(max_element))~~
- HDU1028 Ignatius and the Princess III(DP)
- PLSQL个性化设置
- uboot 2015 添加新的板级支持
- DAC驱动
- iOS简单实现虚线的小方法