方法构建Leaf increment()

wuguiwu 2012-11-15 09:18:01
public class Leaf {
private int i=0;
public 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().increment().print();
}

}
这里的Leaf increment() 可以换成public void increment()吗,请附带原因
...全文
121 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧