public get<R>(key as K, defaultValue as R) as R
Returns the value associated with a key, or a typed default value when the key is absent.
Unlike operator[], this method never raises KeyException for a missing key. The generic return type R is inferred from defaultValue or provided explicitly with get<R>(...). When the key exists, the stored value is cast to R; an incompatible requested type raises a normal type error instead of silently converting the value.
| Parameter | Description |
|---|---|
key | The key to search for. |
defaultValue | The typed value returned when the key is absent. |
The stored value cast to R, or defaultValue.
config as Map<String, Object> = {
"theme": "dark",
"retryCount": 3
}
theme = config.get("theme", "light")
retries = config.get("retryCount", 0)
missing = config.get<Boolean>("missing", false)