Java Boolean Wrapper class is not design properly, which shouldn’t expose such constructor, if it was design after Enum, it would be just two enum values – TRUE, FALSE, and could just do == and !=, similar to boolean primitive did. It is up to developer to decide which String should be considering as “truthy” using Factor design.
When == or != is checked on the Boolean, the boolean primitive is compared.
This is incorrect. Boolean objects are not unboxed for == and !=. The reason “3” is not printed is because test1() and test2() return boolean primitives, so they are unboxed before the function returns.
Java Boolean Wrapper class is not design properly, which shouldn’t expose such constructor, if it was design after Enum, it would be just two enum values – TRUE, FALSE, and could just do == and !=, similar to boolean primitive did. It is up to developer to decide which String should be considering as “truthy” using Factor design.
This is incorrect. Boolean objects are not unboxed for == and !=. The reason “3” is not printed is because test1() and test2() return boolean primitives, so they are unboxed before the function returns.
Thanks Derek !! This has been updated in the quiz.
[…] Java Quiz 22 (Boolean states) […]