Bustikiller
Bustikiller

Reputation: 2508

Split method call into multiple lines

I would like to know which of these options is better in terms of clean (Java) code:

MyClass myObject = new MyClass(
    getParameter1(...), 
    getParameter2(...), 
    getParameter3(...)
);

or this one:

String param1 = getParameter1(...);
String param2 = getParameter2(...);
String param3 = getParameter3(...);

MyClass myObject = new MyClass(param1, param2, param3);

Upvotes: 0

Views: 1058

Answers (2)

Franky
Franky

Reputation: 11

I think it is a duplication of: Getter-Setter and private variables

Clean code does tell you to use getters and setters.

To give you the proper answer, you should describe the scenario.

Upvotes: 0

Naxos84
Naxos84

Reputation: 2038

I'd prefer to use the first one. Cause with the second one you have 3 extra variables that are not used anymore.

Upvotes: 2

Related Questions