this作为返回值
来源:小侦探旅游网
public class ReturnThis { public int age=6; public ReturnThis grow() { age++; return this;//把this 作为返回值,返回grow方法的对象age } public static void main(String[] args) { } }
ReturnThis rt=new ReturnThis(); rt.grow() .grow() .grow(); System.out.println(\"rt的age Feild值是:\"+rt.age);