https://kotlinlang.org logo
Title
a

adam-mcneilly

02/07/2019, 2:56 PM
huh == Boolean.TRUE made it go away
s

Shawn

02/07/2019, 2:57 PM
another oddity to file away for later 🤔
😂 1
a

adam-mcneilly

02/07/2019, 2:57 PM
lmao yep
Wouldn't it still need to unbox to perform this comparison? 🤔
s

Shawn

02/07/2019, 2:58 PM
You know, I’ve been wrangling with that in my head
Wait, no, not in Java since
==
is identity
Hm, wait, no, that probably isn’t explaining it properly either lmao
a

adam-mcneilly

02/07/2019, 3:00 PM
lmao
s

Shawn

02/07/2019, 3:00 PM
I might fire up the bytecode viewer and see what’s different about primitive comparisons
a

adam-mcneilly

02/07/2019, 3:01 PM
I am going to hardcode this property as null and see if it crashes
👨‍🔬 1
It could be a primitive thing though. This could work in the same way that getCount() == 2 works, for example.
👨‍🔬 I come back to report that
config.isTransparentToolbar() == Boolean.TRUE
will not crash if it's null. Thanks for all the help.
k

karelpeeters

02/07/2019, 6:44 PM
I would not do that, ever.
java.lang.Boolean
isn't a proper "dualton", you can create new instances: https://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#Boolean(boolean)
Boolean(true) != Boolean.TRUE
:java:
s

Shawn

02/07/2019, 6:44 PM
aw beans
why is that constructor even public
k

karelpeeters

02/07/2019, 6:45 PM
I don't understand why they did that either 🤔
Probably from a time when effective Java hadn't come out yet and factory methods weren't popular yet. 😒imple_smile:
a

adam-mcneilly

02/07/2019, 7:28 PM
Oh wow. So then what's an alternative to handling this unboxing warning?
s

Shawn

02/07/2019, 7:29 PM
Probably something like
Boolean.TRUE.equals(config.isTransparentToolbar())
if I had to guess
👍 1
it looks terribly unintuitive, though, like I’d be pretty bewildered if I came across that line had Karel not explained the awfulness of
Boolean
to us
l

louiscad

02/07/2019, 7:33 PM
FYI,
Boolean
boxes are cached… because there's only two values to cache. For other primitives (numbers), all values that cover
Byte
(-128 to 127) are cached, at least on Android.
k

karelpeeters

02/07/2019, 7:33 PM
Boolean.valueOf(x)
is cached,
Boolean(x)
can't be.
Bigger question is why is your boolean nullable? Shouldn't that be an enum or something?
a

adam-mcneilly

02/07/2019, 8:56 PM
It's a model object that I get from the server. I make all fields in my data class nullable so it can handle the server not supplying them or possibly sending null.
k

karelpeeters

02/07/2019, 8:56 PM
Okay, makes sense 😒imple_smile:
🙂 1
a

adam-mcneilly

02/07/2019, 9:01 PM
Thank you for your help!