Files
kotlin-fork/backend.native/tests/codegen/branching/when_with_try1.kt
T
2018-05-22 12:07:36 +03:00

22 lines
402 B
Kotlin

package codegen.branching.when_with_try1
import kotlin.test.*
@Test fun runTest() {
println(foo(Any()))
println(foo("zzz"))
println(foo("42"))
}
fun foo(value: Any): Int? {
if (value is CharSequence) {
try {
return value.toString().toInt()
} catch (e: NumberFormatException) {
return null
}
}
else {
return null
}
}