What is the difference between build().perform() and perform()

爱⌒轻易说出口 提交于 2020-02-15 06:47:29

问题


Some articles suggest that now build() is included in perform() itself, while others suggest that build().perform() is used when multiple actions are to be chained together.


回答1:


build() is included in perform(), you can see it in the source code

public void perform() {
    build().perform();
}

The perform() inside the methods calls the perform() method in the inner class BuiltAction.

Calling build().perform() in your code is actually calling build() twice, build().build().perform().

build

Generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).

performe

A convenience method for performing the actions without calling build() first.

This is little misleading (IMO), because build() is being called, even if implicitly.




回答2:


  1. build() - Generates a composite action containing all actions so far, ready to be performed (and resets the internal builder state, so subsequent calls to build() will contain fresh sequences).

  2. perform() A convenience method for performing the actions without calling build() first.

So, whenever going for composite actions (multiple actions) use build().perform(), else perform().




回答3:


build() method in Actions class is use to create chain of action or operation you want to perform.

perform() this method in Actions Class is use to execute chain of action which are build using Action build method.

build().perform() = create chain of actions + execute



来源:https://stackoverflow.com/questions/54053633/what-is-the-difference-between-build-perform-and-perform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!