Skip to content

Files

Latest commit

 

History

History
29 lines (20 loc) · 479 Bytes

SafeCast.md

File metadata and controls

29 lines (20 loc) · 479 Bytes

Pattern: Missing use of safe cast

Issue: -

Description

Found cast could be replaced with safe casts instead.

Example of incorrect code:

fun numberMagic(number: Number) {
    val i = if (number is Int) number else null
    // ...
}

Example of correct code:

fun numberMagic(number: Number) {
    val i = number as? Int
    // ...
}

Further Reading