07-20-2023, 10:07 AM
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)
... but that gives me a type mismatch (apparantly `"John"`, `1` and `true` are not Objects)
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?
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)
... but that gives me a type mismatch (apparantly `"John"`, `1` and `true` are not Objects)
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?