Files
kotlin-fork/compiler/testData/codegen/boxWithStdlib/regressions/kt4262.kt
T
Alexander Udalov af3d56b44e Fix JVM type mapping of arrays of type variables
#KT-4262 Fixed
 #KT-5056 Fixed
2014-05-20 19:22:53 +04:00

11 lines
304 B
Kotlin

fun <E : Enum<E>> Byte.toEnum(clazz : Class<E>) : E =
(clazz.getMethod("values").invoke(null) as Array<E>)[this.toInt()]
enum class Letters { A B C }
fun box(): String {
val clazz = javaClass<Letters>()
val r = 1.toByte().toEnum(clazz)
return if (r == Letters.B) "OK" else "Fail: $r"
}