I need some help on the Kotlin Type system. I hav...
# getting-started
f
I need some help on the Kotlin Type system. I have the following code
Copy code
class TypeFactory {
    val types = mapOf(Pair("String", StringFactory()),
            Pair("Integer", IntegerFactory()),
            Pair("Decimal", DecimalFactory()),
            Pair("UUID", UUIDFactory()),
            Pair("DateTime", DateTimeFactory())
            )
    @Suppress("IMPLICIT_CAST_TO_ANY")
    inline fun <T> get(key: String, value: String) : T? {
        val t  = types[key]!!
        @Suppress("UNCHECKED_CAST")
        return when(t){
            is StringFactory -> t.create(value)
            is IntegerFactory -> t.create(value)
            is DecimalFactory -> t.create(value)
            is UUIDFactory -> t.create(value)
            is DateTimeFactory -> t.create(value)
            else -> null
        } as T?
    }
}
it works, but I am wondering if there is a better way to do it which gives more type information