Why equality checks are preferable over elvis oper...
# announcements
v
Why equality checks are preferable over elvis operator in case, when a boolean variable is nullabe? E.g.
Copy code
val parameter: Boolean? by param()
if (parameter != false) ...
instead of
Copy code
val parameter: Boolean? by param()
if (parameter ?: true) ...
👍 2
d
Less comparisons maybe?
k
I would like some justification for this too, elvis reads better to me.
👍🏼 1
v
I don't know how elvis works beyond the scenes, perhaps, @Dominaezzz is right about comparisons
d
It involves a copy, then an if/else.
k
Copy code
x ?: true
x != false
compiles to
Copy code
x != null ? x : true
Intrinsics.areEqual(x, false) ^ true
Although this whole thing is moot, they should just test which one is fastest and make the compiler always emit that one for both cases.
👍🏼 1
v
Are there any exception handlers involved?
With elvis operator vs equality check
k
Not 100% sure what you're asking but neither method does anything with exceptions.
v
About a hour ago experienced a Null Pointer Exception hell with javafx. Elvis helped a lot
Thus an idea flashed about exception interception