Created
December 14, 2017 20:18
-
-
Save AlexeySoshin/b797cc1b49a2a53237f5f7e6bc8ab02f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using <code>by</code> keyword you can delegate all but overridden methods | |
*/ | |
class HappyMap<K, V>(val map : MutableMap<K, V> = mutableMapOf()) : MutableMap<K, V> by map{ | |
override fun put(key: K, value: V): V? { | |
return map.put(key, value).apply { | |
if (this == null) { | |
println("Yay! $key") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment