public get<R>(key as K, defaultValue as R) as R:
Returns the associated value or a typed default when the key is absent.
The generic return type R is inferred from defaultValue. An existing value is cast to R, preserving static typing for heterogeneous maps.
| Parameter | Description |
|---|---|
key | The key to search for. |
defaultValue | The value returned for an absent key. |
The stored value cast to R, or defaultValue.
config = HashMap<String, Object>()
config["theme"] = "dark"
theme = config.get("theme", "light")
assert theme == "dark"