Is it possible to have a hashmap in Kotlin that takes different value types?
I've tried this:
val template = "Hello {{world}} - {{count}} - {{tf}}"
val context = HashMap<String, Object>()
context.put("world", "John")
context.put("count", 1)
context.put("tf", true)
... 但这给了我一个类型不匹配(显然"John"
、1
和true
不是对象)
In Java you can get around this by creating types new String("John")
, new Integer(1)
, Boolean.TRUE
, I've tried the equivalent in Kotlin, but still getting the type mismatch error.
context.put("tf", Boolean(true))
Any ideas?