Is it possible to have a hashmap in Kotlin that accepts different types of values?
I 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)
... but this gives me a type mismatch (apparantly "John", 1and trueare not objects)
In Java, you can get around this by creating types new String("John"), new Integer(1), Boolean.TRUE, I tried the equivalent in Kotlin, but still get the error type mismatch.
context.put("tf", Boolean(true))
Any ideas?
source
share