return this
是返回当前对象的引用(实际调用这个方法的实例化对象)
如:
public class ReturnTest {
public String a;
public String b;
public String c;
public ReturnTest getA(String a){
this.a = a;
return this;
}
public ReturnTest getB(String b){
this.b = b;
return this;
}
public ReturnTest getC(String c){
this.c = c;
return this;
}
public static void main(String[] args) {
ReturnTest r = new ReturnTest();
r.getA(“hello”).getB(“nihao”).getC(“me?”);
System.out.println(r.a+r.b+r.c);
}
如上例子中,r.getA(“hello”)是return this,即返回ReturnTest 的实例r。
返回值是hellonihaome?