Pattern: Nullable toString
call
Issue: -
Turn on this rule to flag toString
calls with a nullable receiver that may return the string null
.
Example of incorrect code:
fun foo(a: Any?): String {
return a.toString()
}
fun bar(a: Any?): String {
return "$a"
}
Example of correct code:
fun foo(a: Any?): String {
return a?.toString() ?: "-"
}
fun bar(a: Any?): String {
return "${a ?: "-"}"
}