The following code invokes func() in the empty-if case, and it shouldn't:
public class Test {
static boolean func()
{
System.out.println("Func called");
return true;
}
public static void main(String args[]) {
boolean val = true;
if (val || func()) {
}
System.out.println("Not Prevented");
if (val || func()) {
System.out.println("Prevented");
}
}
}
The output is:
Func called
Not Prevented
Prevented
public class Test {
static boolean func()
{
System.out.println("Func called");
return true;
}
public static void main(String args[]) {
boolean val = true;
if (val || func()) {
}
System.out.println("Not Prevented");
if (val || func()) {
System.out.println("Prevented");
}
}
}
The output is:
Func called
Not Prevented
Prevented