Kotlin

Kotlin

Made by DeepSource

null comparison using equals method KT-W1049

Anti-pattern
Major
Autofix

Using 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.

Bad Practice

fun isNull(str: String) = str.equals(null)

Recommended

Prefer == over equals when comparing against null.

fun isNull(str: String) = str == null

Reference