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

We Are Going To Discuss About What is the difference between build().perform() and perform(). So lets Start this Java Article.

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

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

    build() is included in perform(), you can see it in the source code
    public void perform() { build().perform(); }

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

    build() is included in perform(), you can see it in the source code
    public void perform() { build().perform(); }

Solution 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.

Original Author Guy Of This Content

Solution 2

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

Original Author Ankur Singh Of This Content

Solution 3

  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().

Original Author Mohit Rathi Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment