Lets say I have a hash map like this:
private Map<someObject, Boolean> hashMap = new HashMap<>();
And I have two methods like this:
public void methodOne(key) {
if (hashMap.get(key) == null || !hashMap.get(key)) {
//do something
hashMap.put(key, true);
}
}
and
public void methodtwo(key) {
if (hashMap.get(key) != null && hashMap.get(key)) {
//do something else
hashMap.put(key, false);
}
}
My code seems to be working, but I am wondering the logical operation that I am doing in the if statements are valid and wether there is a better way to do it?
The other thing I am wondering is, what would be the result for the following logical operations:
null || truenull || falsenull && truenull && false
null || true == true,null || false == null,null && true == null,null && false == falsenullwithtrueorfalse.nullcan have many meanings, and such operations should not be performed. Java explicitly removed such operations from C/C++.