Sreejith C
Sreejith C

Reputation: 25

What do you call the calling of multiple methods in a single line in java? In the below code we have methods manage(), window() and maximize()

driver.manage().window().maximize();

Upvotes: 1

Views: 601

Answers (3)

robingood
robingood

Reputation: 319

Each call of the method usually returns the same object which has been calling it (like return this), allowing to call other methods on the same object. It can however return other objects which can also be method-chained or even void if it is a terminal method.

Upvotes: 1

Slaw
Slaw

Reputation: 45906

This is known as method chaining, as stated in Thibstars' answer. In your case it's a more concise way of writing:

WebDriver driver = ...; // get instance from somewhere
WebDriver.Options options = driver.manage();
WebDriver.Window window = options.window();
window.maximize();

Note: The class types are assumed based on the tag and method names.

Upvotes: 2

Thibstars
Thibstars

Reputation: 1083

That would be Method Chaining.

Upvotes: 5

Related Questions