Reputation: 101
HashMap<String, Boolean> mAchBools = new HashMap<String, Boolean>(){{
put("myBool1", false);
}
};
HashMap<String, Integer> mAchInts = new HashMap<String, Integer>(){{
put("myInt1", 0);
}
};
boolean isEmpty() {
for (boolean b : mAchBools.values()) if (b) return false;
for (int i : mAchInts.values()) if (i != 0) return false;
return true;
}
I create a HashMap will Booleans and a HashMap with Integers. Now I want a method to check and see if the values are "empty" (all booleans are false and all integers are 0).
I run Debugger and I can see that my boolean in the Hashmap is false, but my method "isEmpty" still returns false.
Why does my "isEmpty" check fail? I think it's a difference between boolean and Boolean but I'm not sure.
Upvotes: 0
Views: 489
Reputation: 7315
Java automatically converts between Boolean <> boolean and int <> Integer. So your code is technically correct as written.
Upvotes: 1