return this的用法
来源:互联网 发布:火爆网络女神雅典娜 编辑:程序博客网 时间:2024/05/19 10:55
每次返回类实例,用return this;
- class Test2 {
- String s="";
- public static void main(String[] args) {
- Test2 t = new Test2();
- t.method("111");
- t.method("222");
- t.method("333");
- t.method2();
- }
- public Test2 method(String sb) {
- s+=sb;
- return this;
- }
- public void method2() {
- System.out.println(s);
- }
- }
结果: 111222333
- class Test
- {
- public static void main(String[] args)
- {
- Test t = new Test().method();//返回当前这个类的实例给t
- t.method2();
- }
- public Test method()
- {
- return this;
- }
- public void method2()
- {
- System.out.println( "Hello Beijing 2008! ");
- }
- }
return this就是返回当前这个类的一个实例 this 就是代表当前这个类的一个实例.
原文参考:
http://hi.baidu.com/rague/blog/item/5a44a882a0d1afa70cf4d2b9.html
- return this的用法
- return this 的用法笔记
- 第三课 return关键字的用法、toString()方法、this关键字
- c++中return this和return *this的区别
- return的用法
- java return的用法
- return语句的用法
- return的用法
- return 的基本用法
- return的简单用法
- 关键字return的用法
- 【JavaScript】return的用法
- return this与return *this
- return *this和return this
- return *this和return this
- js之return return false return true 的用法
- 关于C++ return * this的理解
- 关于C++ return *this的理解
- 万方专利软件特别说明
- WML计费页面
- 如何让程序在安装后自动运行
- 小克儿的成长~~
- 文件类型和从属关系
- return this的用法
- 切换环境,MTM能力,区分移动还是联通
- 我是差不多
- Asp.NET 多层登陆
- 在Symbian应用里嵌入汇编代码
- VBScript 中的错误处理...
- 重新启动设备代码,扩展窗口到全屏,得到剩余内存,读写GIF的帧信息,得到系统的软件版本号
- 整型变量与字节数组的相互转换
- 制作动态网站比较好用的软件工具