Skip to content

Files

Latest commit

 

History

History
27 lines (18 loc) · 446 Bytes

UnsafeCast.md

File metadata and controls

27 lines (18 loc) · 446 Bytes

Pattern: Use of unsafe cast

Issue: -

Description

Reports casts which are unsafe. In case the cast is not possible it will throw an exception.

Example of incorrect code:

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

Example of correct code:

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

Further Reading