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?
When current in an electric circuit abruptly rises due to some default in the circuit it is called short – circuiting. Two precautions to Prevent it are:i Wires should be well insulated. ii Too many appliances should not be connected to a single socket. The colour of insulation of earth wire green.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With