KT.UNNECESSARY_SAFE_CALL

Unnecessary safe call operator (?.)

Reports unnecessary safe call operators (?.) that can be removed by the user.

Noncompliant Code

Copy
val a: String = ""
val b = a?.length

Compliant Code

Copy
val a: String? = null
val b = a?.length

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html