Which of these two is the better way of doing the same thing -
public void someMethod(String s, boolean bool02){
boolean bool01 = s!=null;
if(bool01==bool02){
doSomething();
}
}
OR
public void someMethod(String s, boolean bool02){
List<String> list=new ArrayList<String>();
if(s!=null && bool02){
doSomething();
}
}
The way I understand it is, Option 1 -
- Computes s!=null
- Set it to bool01
- Compares bool01 to bool02
and Option 2 -
- Computes s!=null
- Compares it with true
- Compares bool02 to true(depending if step 2 was true)
This is not a big deal but its bugging me to know which one is better. Or does the compiler optimization(if any) converts both of them to the same thing?