2 ms·
> HashMaps not having non-nullable values Not sure about that example since it’s easy to do class MapWithDefault<K, V>( private val map: Map<K, V>,
by dullcrisp 3y ago
> HashMaps not having non-nullable values
Not sure about that example since it’s easy to do
class MapWithDefault<K, V>(
private val map: Map<K, V>,
private val defaultValue: V
) {
fun get(k: K) = map.get(k) ?: defaultValue
// …
}
Edit: or I’m sure there’s something that does this already.