How to do method chaining in Java? o.m1().m2().m3().m4()

后端 未结 6 797
渐次进展
渐次进展 2020-11-29 02:33

I\'ve seen in many Java code notation that after a method we call another, here is an example.

Toast.makeText(text).setGravity(Gravity.TOP, 0, 0).setView(lay         


        
6条回答
  •  离开以前
    2020-11-29 02:56

    Search for builder pattern or fluent interface on google to have more details about this.

    Return 'this' at the end of your method can do the trick in most cases.

提交回复
热议问题