KT.UNSAFE_CAST

Cast that will never succeed

Reports casts that will never succeed.

Noncompliant Code

Copy
fun foo(s: String) {
    println(s as Int)
}

fun bar(s: String) {
    println(s as? Int)
}

Compliant Code

Copy
fun foo(s: Any) {
    println(s as Int)
}

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