KT.CAST_TO_NULLABLE_TYPE
Cast to nullable types
Disallow to cast to nullable types. There are cases where as String? is misused as safe cast (as? String). So if you want to prevent those cases, turn on this rule.
Noncompliant Code
Copy
fun foo(a: Any?) {
val x: String? = a as String? // If 'a' is not String, ClassCastException will be thrown.
}
Compliant Code
Copy
fun foo(a: Any?) {
val x: String? = a as? String
}