Reputation: 6948
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
Upvotes: 3
Views: 225
Reputation: 1625
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()
}
Upvotes: 2