Rok Oblak
05/23/2025, 7:34 AM?: false
implies "default to false". I find this more readable than == ...
.Klitos Kyriacou
05/23/2025, 7:44 AM== true
.Riccardo Lippolis
05/23/2025, 7:59 AM?: false
. I found this discussion where someone suspected it had something to do with the operator precedence rules (==
being lower than ?:
), although I could also not come up with a good example for this yet.
Another possible reason I can think of is that it might produce more optimal byte code? (equality check instead of branching), although this might be something the compiler is smart enough to optimize by itself...christophsturm
05/23/2025, 8:05 AMRoman Golyshev
05/23/2025, 8:27 AMchristophsturm
05/23/2025, 8:38 AMephemient
05/23/2025, 11:15 PMBoolean?
type is inhabited by 3 values: null
, false
, and true
. using ==
makes it obvious which one is being singled outephemient
05/23/2025, 11:16 PMnull
when it's just another value that's properly tracked by the type systemRok Oblak
05/24/2025, 4:51 AMephemient
05/24/2025, 11:58 PM(Boolean?) -> Boolean
, which are
{ false }
{ true }
{ it == true }
{ it == false }
{ it == null }
{ it != true }
{ it != false }
{ it != null }
you can't express most of them with ?:
christophsturm
05/25/2025, 10:05 AMephemient
05/26/2025, 9:12 PM{ it ?: true }
{ it ?: false }
{ !(it ?: true) }
{ !(it ?: false) }
is not an improvementRok Oblak
05/27/2025, 4:11 AMephemient
05/27/2025, 2:29 PMModel(
editable = props["readonly"]?.toBoolean() != true,
)