klyn.collections.Map.get
method
public get<R>(key as K, defaultValue as R) as R
Description

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.

Parameters
ParameterDescription
keyThe key to search for.
defaultValueThe typed value returned when the key is absent.
Returns

The stored value cast to R, or defaultValue.

Example
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)