Inspectopedia Help

Safe cast with 'return' should be replaced with 'if' type check

Reports safe cast with return that can be replaced with if type check.

Using corresponding functions makes your code simpler.

The quick-fix replaces the safe cast with if type check.

Example:

fun test(x: Any) { x as? String ?: return }

After the quick-fix is applied:

fun test(x: Any) { if (x !is String) return }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023