Objectname.methodone()
.methodtwo()
.methodthree()
.methodfour();
上面这些说法是否相同
Objectname.methodone();
Objectname.methodtwo();
Objectname.methodthree();
Objectname.methodfour();
谢谢
最佳答案
这取决于methodone
、methodtwo
、method Three
和methodfour
的返回类型。发生的事情是您在 Objectname
上调用 methodone
,在 methodone
的返回类型上调用 methodtwo
等等.
如果 methodone
到 methodfour
都返回 this
,那么是的,结果是一样的。
这被称为 method chaining .
关于java - 我想知道这个 Java 代码块中发生了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967534/