Skip to content

Instantly share code, notes, and snippets.

@AlexeySoshin
Created December 14, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexeySoshin/b797cc1b49a2a53237f5f7e6bc8ab02f to your computer and use it in GitHub Desktop.
Save AlexeySoshin/b797cc1b49a2a53237f5f7e6bc8ab02f to your computer and use it in GitHub Desktop.
/**
* 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