MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/hefap9/val_is_a_boolean_value/fvt4eqa/?context=9999
r/badcode • u/Bluebearsuper • Jun 23 '20
58 comments sorted by
View all comments
129
if (val == true) { return true; } else { return false; }
106 u/[deleted] Jun 23 '20 if (val == true) { return true; }else if (val != true) { return false; }else { throw "this should never happen"; }return false; 26 u/NightHunter311 Jun 23 '20 There's a chance val might be null... 16 u/[deleted] Jun 23 '20 edited Jun 23 '20 That depends on the language. If it's a C-style language or, as in this case, Java, then no 3 u/someone4else Jun 24 '20 Well, if you use Boolean, then you can get this 4 u/[deleted] Jun 24 '20 Pretty sure it doesn't work because a Boolean doesn't equal to true or false, you'd have to call the Boolean.booleanValue() method 9 u/Kernel_Internal Jun 24 '20 autoboxing yo 3 u/[deleted] Jun 24 '20 Ahh I stand corrected
106
if (val == true) { return true; }else if (val != true) { return false; }else { throw "this should never happen"; }return false;
if (val == true) { return true; }
else if (val != true) { return false; }
else { throw "this should never happen"; }
return false;
26 u/NightHunter311 Jun 23 '20 There's a chance val might be null... 16 u/[deleted] Jun 23 '20 edited Jun 23 '20 That depends on the language. If it's a C-style language or, as in this case, Java, then no 3 u/someone4else Jun 24 '20 Well, if you use Boolean, then you can get this 4 u/[deleted] Jun 24 '20 Pretty sure it doesn't work because a Boolean doesn't equal to true or false, you'd have to call the Boolean.booleanValue() method 9 u/Kernel_Internal Jun 24 '20 autoboxing yo 3 u/[deleted] Jun 24 '20 Ahh I stand corrected
26
There's a chance val might be null...
16 u/[deleted] Jun 23 '20 edited Jun 23 '20 That depends on the language. If it's a C-style language or, as in this case, Java, then no 3 u/someone4else Jun 24 '20 Well, if you use Boolean, then you can get this 4 u/[deleted] Jun 24 '20 Pretty sure it doesn't work because a Boolean doesn't equal to true or false, you'd have to call the Boolean.booleanValue() method 9 u/Kernel_Internal Jun 24 '20 autoboxing yo 3 u/[deleted] Jun 24 '20 Ahh I stand corrected
16
That depends on the language. If it's a C-style language or, as in this case, Java, then no
3 u/someone4else Jun 24 '20 Well, if you use Boolean, then you can get this 4 u/[deleted] Jun 24 '20 Pretty sure it doesn't work because a Boolean doesn't equal to true or false, you'd have to call the Boolean.booleanValue() method 9 u/Kernel_Internal Jun 24 '20 autoboxing yo 3 u/[deleted] Jun 24 '20 Ahh I stand corrected
3
Well, if you use Boolean, then you can get this
4 u/[deleted] Jun 24 '20 Pretty sure it doesn't work because a Boolean doesn't equal to true or false, you'd have to call the Boolean.booleanValue() method 9 u/Kernel_Internal Jun 24 '20 autoboxing yo 3 u/[deleted] Jun 24 '20 Ahh I stand corrected
4
Pretty sure it doesn't work because a Boolean doesn't equal to true or false, you'd have to call the Boolean.booleanValue() method
9 u/Kernel_Internal Jun 24 '20 autoboxing yo 3 u/[deleted] Jun 24 '20 Ahh I stand corrected
9
autoboxing yo
3 u/[deleted] Jun 24 '20 Ahh I stand corrected
Ahh I stand corrected
129
u/INeedAFreeUsername Jun 23 '20