null
comparison using equals
method KT-W1049Using equals
to compare an object with null
is bad practice. If an object has to be checked for null
,
consider using the ==
operator directly. This makes the code more concise. Furthermore, comparison using
==
also prevents mistakes caused by forgetting to handle null
in the equals()
implementation, or if the object you are calling equals()
on is itself null
.
fun isNull(str: String) = str.equals(null)
Prefer ==
over equals
when comparing against null
.
fun isNull(str: String) = str == null