``` class CounterMap(val map: MutableMap<String...
# getting-started
a
Copy code
class CounterMap(val map: MutableMap<String, Int>): MutableMap<String, Int> by map {
    override fun put(key: String, value: Int): Int? {
        val previousValue = map[key]
        
        map[key] = (previousValue ?: 0 ) + value
        	
        return previousValue
    }
}
n
d3xter: Actually I think I would have to override get: class CounterMap<K, V>(val map: MutableMap<K, V>, val default: V): MutableMap<K, V> by map { override fun get(key: K): V { return map[key] ?: default } }
also asked in #stdlib , thanks for the tip
a
you are right. its better to override
get()