mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
27 lines
511 B
Kotlin
Vendored
27 lines
511 B
Kotlin
Vendored
class EncapsulatedEnum<T : Enum<T>>(val value: T)
|
|
|
|
enum class MyEnum(val value: String) {
|
|
VALUE_A("OK"),
|
|
VALUE_B("fail"),
|
|
}
|
|
|
|
private fun crash(encapsulated: EncapsulatedEnum<*>) {
|
|
val myEnum = encapsulated.value
|
|
if (myEnum !is MyEnum) {
|
|
return
|
|
}
|
|
|
|
when (myEnum) {
|
|
MyEnum.VALUE_A -> res = myEnum.value
|
|
MyEnum.VALUE_B -> res = myEnum.value
|
|
}
|
|
}
|
|
|
|
var res = "fail"
|
|
|
|
fun box(): String {
|
|
crash(EncapsulatedEnum(MyEnum.VALUE_A))
|
|
return res
|
|
}
|
|
|
|
// 1 LOOKUPSWITCH |