Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preventing short-circuiting?

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?

like image 990
Lukáš Rutar Avatar asked Apr 22 '14 14:04

Lukáš Rutar


People also ask

What is short circuiting how can it be prevented Class 10?

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.


1 Answers

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.

like image 156
Maroun Avatar answered Oct 26 '22 16:10

Maroun