Kotlin mix type

Viewed 112

How to limit the type instead of using Any in value of map?

val mixType = Map<String, String or Boolean or Int>()  // something I like
val anyType = Map<String, Any>()  // the scope is too large
1 Answers

I would suggest using a sealed class here:

sealed class MyValue {
    class IntValue(val value: Int): MyValue()
    class BooleanValue(val value: String): MyValue()
    class StringValue(val value: Boolean): MyValue()
}
Related