suppose i have two functions, boolean fA()
and boolean fB()
if i write another function function(boolean b)
and I call function(fA()||fB())
then fB()
might not be executed, if fA()
returns true.
I like this feature, but here I need both functions to execute. Obvious implementation:
boolean temp = fA();
function(fB()||temp);
is ugly, and needed extra line makes it less readable.
is there an way to force evaluation in Java or other elegant way to write this in one line without helper variable?
You can use |
instead, it doesn't do short-circuit evaluation:
function(fB() | fA());
This ensures that even if fB
is true
, fA
will be called.