关于return this的问题.
Qlin 2005-10-21 02:20:05 RT.. 代码如下.
public class Leaf
{
int i = 0;
Leaf increment()
{
i++;
return this;
}
void print()
{
System.out.println("i = " + i);
}
public static void main(String[] args)
{
Leaf x = new Leaf();
x.increment().increment().increment().print();
}
}
程序输出的结果是 i = 3 .
请问.这里调用方法increment() 返回 this,为什么会返回 i 的值呢.? 谢谢.