Conditional method chaining in java
What is the best possible way to chain methods together? In my scenario, there are four methods. If the output of the first method is true
, it has to call the second method.
For Example:
flag = method1();
if (flag){
flag = method2();
}
if (flag){
method3();
}
// and so on for next methods ..
java
add a comment |
What is the best possible way to chain methods together? In my scenario, there are four methods. If the output of the first method is true
, it has to call the second method.
For Example:
flag = method1();
if (flag){
flag = method2();
}
if (flag){
method3();
}
// and so on for next methods ..
java
Use a nested set of conditional operators. It won't be legible but it will work.
– nicomp
Dec 21 '18 at 19:46
Do you need to returnflag
after the last method has been executed?
– Federico Peralta Schaffner
Dec 21 '18 at 19:50
1
"best" by what metric?
– TylerH
Dec 21 '18 at 22:52
add a comment |
What is the best possible way to chain methods together? In my scenario, there are four methods. If the output of the first method is true
, it has to call the second method.
For Example:
flag = method1();
if (flag){
flag = method2();
}
if (flag){
method3();
}
// and so on for next methods ..
java
What is the best possible way to chain methods together? In my scenario, there are four methods. If the output of the first method is true
, it has to call the second method.
For Example:
flag = method1();
if (flag){
flag = method2();
}
if (flag){
method3();
}
// and so on for next methods ..
java
java
edited Dec 21 '18 at 20:00
Federico Peralta Schaffner
22k43370
22k43370
asked Dec 21 '18 at 19:42
user10821509
624
624
Use a nested set of conditional operators. It won't be legible but it will work.
– nicomp
Dec 21 '18 at 19:46
Do you need to returnflag
after the last method has been executed?
– Federico Peralta Schaffner
Dec 21 '18 at 19:50
1
"best" by what metric?
– TylerH
Dec 21 '18 at 22:52
add a comment |
Use a nested set of conditional operators. It won't be legible but it will work.
– nicomp
Dec 21 '18 at 19:46
Do you need to returnflag
after the last method has been executed?
– Federico Peralta Schaffner
Dec 21 '18 at 19:50
1
"best" by what metric?
– TylerH
Dec 21 '18 at 22:52
Use a nested set of conditional operators. It won't be legible but it will work.
– nicomp
Dec 21 '18 at 19:46
Use a nested set of conditional operators. It won't be legible but it will work.
– nicomp
Dec 21 '18 at 19:46
Do you need to return
flag
after the last method has been executed?– Federico Peralta Schaffner
Dec 21 '18 at 19:50
Do you need to return
flag
after the last method has been executed?– Federico Peralta Schaffner
Dec 21 '18 at 19:50
1
1
"best" by what metric?
– TylerH
Dec 21 '18 at 22:52
"best" by what metric?
– TylerH
Dec 21 '18 at 22:52
add a comment |
7 Answers
7
active
oldest
votes
Use the &&
logical AND
operator:
if (method1() && method2() && method3() && method4()) {
........
}
Java evaluates this condition from left to right.
If any of the methods returns false
, then the evaluation stops, because the final result is false
(Short Circuit Evaluation).
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
8
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
6
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
2
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
|
show 7 more comments
if flag
is not needed somewhere later on then @forpas's answer is the way to go otherwise I'd do:
flag = method1() && method2() && method3() && method4()
add a comment |
To use the short circuit but keep it more readable, you can do
boolean flag = method1();
flag = flag && method2();
flag = flag && method3();
And so on. Note you can't use flag &= methodX()
because that doesn't short circuit.
add a comment |
First and foremost I'd like to state that this answer is by no means more efficient than this answer or this answer rather it's just another way in which you can accomplish the task at hand while maintaining the short-shircuting requirement of yours.
So first step is to create a method as such:
public static boolean apply(BooleanSupplier... funcs){
return Arrays.stream(funcs).allMatch(BooleanSupplier::getAsBoolean);
}
This function consumes any number of functions that have the signature () -> boolean
i.e. a supplier (a function taking no inputs and returns a boolean result).
Then you can call it as follows using a method reference:
if(apply(Main::method1,
Main::method2,
Main::method3,
Main::method4)){ ... };
Where Main
is the class where the methods are defined.
or lambda:
if(apply(() -> method1(),
() -> method2(),
() -> method3(),
() -> method4())){ ... };
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
add a comment |
Nested conditional operators would solve this:
flag = method1() ? (method2() ? method3(): false): false;
nice +1, you can simplify it toflag = method1() && (method2() && method3());
. assumingflag
is needed after the condtions then this is a good approach.
– Aomine
Dec 21 '18 at 19:51
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
1
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
add a comment |
You can use the &&
operator :
boolean flag = method1() && method2() && method3() && method4() && ...;
Do whatever with flag
.
add a comment |
incase the methods truth values have to be saved or other side-effects have to happen:
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
you shouldn't want this and it's... unexpected.
but this is a readable way of adding additional statements to each code path.
otherwise: do it differently or fall back on ifs.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53890008%2fconditional-method-chaining-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use the &&
logical AND
operator:
if (method1() && method2() && method3() && method4()) {
........
}
Java evaluates this condition from left to right.
If any of the methods returns false
, then the evaluation stops, because the final result is false
(Short Circuit Evaluation).
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
8
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
6
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
2
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
|
show 7 more comments
Use the &&
logical AND
operator:
if (method1() && method2() && method3() && method4()) {
........
}
Java evaluates this condition from left to right.
If any of the methods returns false
, then the evaluation stops, because the final result is false
(Short Circuit Evaluation).
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
8
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
6
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
2
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
|
show 7 more comments
Use the &&
logical AND
operator:
if (method1() && method2() && method3() && method4()) {
........
}
Java evaluates this condition from left to right.
If any of the methods returns false
, then the evaluation stops, because the final result is false
(Short Circuit Evaluation).
Use the &&
logical AND
operator:
if (method1() && method2() && method3() && method4()) {
........
}
Java evaluates this condition from left to right.
If any of the methods returns false
, then the evaluation stops, because the final result is false
(Short Circuit Evaluation).
edited Dec 21 '18 at 20:02
answered Dec 21 '18 at 19:46
forpas
8,8441421
8,8441421
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
8
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
6
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
2
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
|
show 7 more comments
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
8
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
6
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
2
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
That doesn't put anything in flag.
– nicomp
Dec 21 '18 at 19:47
8
8
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
The flag is not needed this way.
– forpas
Dec 21 '18 at 19:48
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
This is hacker way :) But makes code, probably, hard to read.
– Koziołek
Dec 21 '18 at 19:54
6
6
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
@Koziołek If you know what you're doing, it is not hard to read.
– forpas
Dec 21 '18 at 19:55
2
2
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
@Koziołek as I said If you know what you're doing....
– forpas
Dec 21 '18 at 20:01
|
show 7 more comments
if flag
is not needed somewhere later on then @forpas's answer is the way to go otherwise I'd do:
flag = method1() && method2() && method3() && method4()
add a comment |
if flag
is not needed somewhere later on then @forpas's answer is the way to go otherwise I'd do:
flag = method1() && method2() && method3() && method4()
add a comment |
if flag
is not needed somewhere later on then @forpas's answer is the way to go otherwise I'd do:
flag = method1() && method2() && method3() && method4()
if flag
is not needed somewhere later on then @forpas's answer is the way to go otherwise I'd do:
flag = method1() && method2() && method3() && method4()
edited Dec 21 '18 at 20:00
answered Dec 21 '18 at 19:54
Aomine
40.3k73870
40.3k73870
add a comment |
add a comment |
To use the short circuit but keep it more readable, you can do
boolean flag = method1();
flag = flag && method2();
flag = flag && method3();
And so on. Note you can't use flag &= methodX()
because that doesn't short circuit.
add a comment |
To use the short circuit but keep it more readable, you can do
boolean flag = method1();
flag = flag && method2();
flag = flag && method3();
And so on. Note you can't use flag &= methodX()
because that doesn't short circuit.
add a comment |
To use the short circuit but keep it more readable, you can do
boolean flag = method1();
flag = flag && method2();
flag = flag && method3();
And so on. Note you can't use flag &= methodX()
because that doesn't short circuit.
To use the short circuit but keep it more readable, you can do
boolean flag = method1();
flag = flag && method2();
flag = flag && method3();
And so on. Note you can't use flag &= methodX()
because that doesn't short circuit.
edited Dec 21 '18 at 21:30
answered Dec 21 '18 at 20:05
daniu
7,28021635
7,28021635
add a comment |
add a comment |
First and foremost I'd like to state that this answer is by no means more efficient than this answer or this answer rather it's just another way in which you can accomplish the task at hand while maintaining the short-shircuting requirement of yours.
So first step is to create a method as such:
public static boolean apply(BooleanSupplier... funcs){
return Arrays.stream(funcs).allMatch(BooleanSupplier::getAsBoolean);
}
This function consumes any number of functions that have the signature () -> boolean
i.e. a supplier (a function taking no inputs and returns a boolean result).
Then you can call it as follows using a method reference:
if(apply(Main::method1,
Main::method2,
Main::method3,
Main::method4)){ ... };
Where Main
is the class where the methods are defined.
or lambda:
if(apply(() -> method1(),
() -> method2(),
() -> method3(),
() -> method4())){ ... };
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
add a comment |
First and foremost I'd like to state that this answer is by no means more efficient than this answer or this answer rather it's just another way in which you can accomplish the task at hand while maintaining the short-shircuting requirement of yours.
So first step is to create a method as such:
public static boolean apply(BooleanSupplier... funcs){
return Arrays.stream(funcs).allMatch(BooleanSupplier::getAsBoolean);
}
This function consumes any number of functions that have the signature () -> boolean
i.e. a supplier (a function taking no inputs and returns a boolean result).
Then you can call it as follows using a method reference:
if(apply(Main::method1,
Main::method2,
Main::method3,
Main::method4)){ ... };
Where Main
is the class where the methods are defined.
or lambda:
if(apply(() -> method1(),
() -> method2(),
() -> method3(),
() -> method4())){ ... };
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
add a comment |
First and foremost I'd like to state that this answer is by no means more efficient than this answer or this answer rather it's just another way in which you can accomplish the task at hand while maintaining the short-shircuting requirement of yours.
So first step is to create a method as such:
public static boolean apply(BooleanSupplier... funcs){
return Arrays.stream(funcs).allMatch(BooleanSupplier::getAsBoolean);
}
This function consumes any number of functions that have the signature () -> boolean
i.e. a supplier (a function taking no inputs and returns a boolean result).
Then you can call it as follows using a method reference:
if(apply(Main::method1,
Main::method2,
Main::method3,
Main::method4)){ ... };
Where Main
is the class where the methods are defined.
or lambda:
if(apply(() -> method1(),
() -> method2(),
() -> method3(),
() -> method4())){ ... };
First and foremost I'd like to state that this answer is by no means more efficient than this answer or this answer rather it's just another way in which you can accomplish the task at hand while maintaining the short-shircuting requirement of yours.
So first step is to create a method as such:
public static boolean apply(BooleanSupplier... funcs){
return Arrays.stream(funcs).allMatch(BooleanSupplier::getAsBoolean);
}
This function consumes any number of functions that have the signature () -> boolean
i.e. a supplier (a function taking no inputs and returns a boolean result).
Then you can call it as follows using a method reference:
if(apply(Main::method1,
Main::method2,
Main::method3,
Main::method4)){ ... };
Where Main
is the class where the methods are defined.
or lambda:
if(apply(() -> method1(),
() -> method2(),
() -> method3(),
() -> method4())){ ... };
edited Dec 21 '18 at 22:44
answered Dec 21 '18 at 22:27
Aomine
40.3k73870
40.3k73870
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
add a comment |
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
This one is likely more readable if the list is more than 3 or 4.
– jpmc26
Dec 22 '18 at 1:18
add a comment |
Nested conditional operators would solve this:
flag = method1() ? (method2() ? method3(): false): false;
nice +1, you can simplify it toflag = method1() && (method2() && method3());
. assumingflag
is needed after the condtions then this is a good approach.
– Aomine
Dec 21 '18 at 19:51
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
1
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
add a comment |
Nested conditional operators would solve this:
flag = method1() ? (method2() ? method3(): false): false;
nice +1, you can simplify it toflag = method1() && (method2() && method3());
. assumingflag
is needed after the condtions then this is a good approach.
– Aomine
Dec 21 '18 at 19:51
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
1
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
add a comment |
Nested conditional operators would solve this:
flag = method1() ? (method2() ? method3(): false): false;
Nested conditional operators would solve this:
flag = method1() ? (method2() ? method3(): false): false;
answered Dec 21 '18 at 19:50
nicomp
2,51921230
2,51921230
nice +1, you can simplify it toflag = method1() && (method2() && method3());
. assumingflag
is needed after the condtions then this is a good approach.
– Aomine
Dec 21 '18 at 19:51
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
1
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
add a comment |
nice +1, you can simplify it toflag = method1() && (method2() && method3());
. assumingflag
is needed after the condtions then this is a good approach.
– Aomine
Dec 21 '18 at 19:51
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
1
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
nice +1, you can simplify it to
flag = method1() && (method2() && method3());
. assuming flag
is needed after the condtions then this is a good approach.– Aomine
Dec 21 '18 at 19:51
nice +1, you can simplify it to
flag = method1() && (method2() && method3());
. assuming flag
is needed after the condtions then this is a good approach.– Aomine
Dec 21 '18 at 19:51
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine I think that would be better answer than this
– eis
Dec 21 '18 at 19:52
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
@Aomine but the conditional operator get so little respect! :)
– nicomp
Dec 21 '18 at 19:53
1
1
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
@nicomp right, i'll post it as an answer then :). #eis sure thing.
– Aomine
Dec 21 '18 at 19:54
add a comment |
You can use the &&
operator :
boolean flag = method1() && method2() && method3() && method4() && ...;
Do whatever with flag
.
add a comment |
You can use the &&
operator :
boolean flag = method1() && method2() && method3() && method4() && ...;
Do whatever with flag
.
add a comment |
You can use the &&
operator :
boolean flag = method1() && method2() && method3() && method4() && ...;
Do whatever with flag
.
You can use the &&
operator :
boolean flag = method1() && method2() && method3() && method4() && ...;
Do whatever with flag
.
answered Dec 21 '18 at 20:03
fastcodejava
24k19109162
24k19109162
add a comment |
add a comment |
incase the methods truth values have to be saved or other side-effects have to happen:
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
you shouldn't want this and it's... unexpected.
but this is a readable way of adding additional statements to each code path.
otherwise: do it differently or fall back on ifs.
add a comment |
incase the methods truth values have to be saved or other side-effects have to happen:
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
you shouldn't want this and it's... unexpected.
but this is a readable way of adding additional statements to each code path.
otherwise: do it differently or fall back on ifs.
add a comment |
incase the methods truth values have to be saved or other side-effects have to happen:
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
you shouldn't want this and it's... unexpected.
but this is a readable way of adding additional statements to each code path.
otherwise: do it differently or fall back on ifs.
incase the methods truth values have to be saved or other side-effects have to happen:
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
you shouldn't want this and it's... unexpected.
but this is a readable way of adding additional statements to each code path.
otherwise: do it differently or fall back on ifs.
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
boolean flag;
switch(1){
case 1: flag = method1();
//additional code goes here
if(!flag) break;
case 2: flag = method2();
//additional code goes here
if(!flag) break;
....
default: flag = method10();
if(!flag) break;
}
answered Dec 21 '18 at 21:13
RecurringError
623
623
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53890008%2fconditional-method-chaining-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use a nested set of conditional operators. It won't be legible but it will work.
– nicomp
Dec 21 '18 at 19:46
Do you need to return
flag
after the last method has been executed?– Federico Peralta Schaffner
Dec 21 '18 at 19:50
1
"best" by what metric?
– TylerH
Dec 21 '18 at 22:52