klyn.collections.MapCollection.get
method

    public get<R>(key as K, defaultValue as R) as R

Description

Returns the value associated with the key, or the provided default value when the key is absent.

This method is intentionally different from `operator[]`: it never raises `KeyException` for a missing key.

The return type is the generic type `R`, inferred from `defaultValue` or provided explicitly with `get<R>(...)`. This is useful when a map stores heterogeneous values as `Object`: callers still get a statically typed result at the call site. If the key exists, the stored value is cast to `R`; a wrong expected type is therefore a real type error instead of a silent conversion.

Parameters

Parameter | Description
--- | ---
`key` | The key to search for.
`defaultValue` | The typed value returned when the key is absent.

Returns

The stored value cast to `R`, or `defaultValue`.

Example

    import klyn.collections

    config as MapCollection<String, Object> = {
    "theme": "dark",
    "retryCount": 3
    }

    theme as String = config.get("theme", "light")            # R is String
    retries as Int = config.get("retryCount", 0)
    fallback as Boolean = config.get("missingFlag", false)
    explicit as String = config.get<String>("theme", "light") # Same type, explicit R.