mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-10 08:31:29 +00:00
22 lines
436 B
Kotlin
22 lines
436 B
Kotlin
fun test1<T>() = null as T
|
|
fun test2<T>(): T {
|
|
val a : Any? = null
|
|
return a as T
|
|
}
|
|
|
|
fun test3<T: Any>() = null as T
|
|
|
|
fun box(): String {
|
|
if (test1<Int?>() != null) return "fail: test1"
|
|
if (test2<Int?>() != null) return "fail: test2"
|
|
var result3 = "fail"
|
|
try {
|
|
test3<Int>()
|
|
}
|
|
catch(e: TypeCastException) {
|
|
result3 = "OK"
|
|
}
|
|
if (result3 != "OK") return "fail: test3"
|
|
return "OK"
|
|
}
|