Fredrik Pe
03/21/2019, 1:50 PMif (list?.isEmpty())
not allowed when if (list?.isEmpty() == true)
is? You are still not specifying null behaviour...diesieben07
03/21/2019, 1:50 PMtrue
is equal to true
. false
, null
and any other value is not equal to true
.fred.deschenes
03/21/2019, 1:51 PMlist?.isEmpty()
will return null if list
is nullShawn
03/21/2019, 1:52 PMlist?.isEmpty()
returns Boolean?
and comparing it to true
lets you check if it’s true. false
and null
are two other states the if statement can’t make assumptions about. “not specifying null behavior” is only important if you’re using the if
as an assignment expression, otherwise you just need to give it a non-nullable Boolean
Fredrik Pe
03/21/2019, 2:18 PMdiesieben07
03/21/2019, 2:18 PMif (a == null)
otherwise?Fredrik Pe
03/21/2019, 2:21 PMfun Int?.equals(other: Int?): Boolean
diesieben07
03/21/2019, 2:22 PM==
.Fredrik Pe
03/21/2019, 3:07 PMSiebelsTim
03/21/2019, 3:28 PMlist != null && list.isEmpty()
or list?.isEmpty() ?: false
if that's better for you.Justin
03/22/2019, 1:22 AMIterable?.isEmptyOrNull() = this == null || this.isEmpty()
or make it more specific to the classes you need to use it for