I m having trouble while writing if statements as follows:
public void foo(List<String> list)
{
if(list == null || list.isEmpty()){
// something
}
// else
}
here is what bothers me: if list is null list.IsEmpty() would fail (throw exception, i m calling a method on a null object), because list is null. However, since I m doing || (or) if list is null (which is true) , it would execute the second block. which would throw exception.
is this correct? in english, if list if null or empty makes sense. is this the case here?
WHat about for && ? or short circuits?
Thanks.