north
02/28/2017, 12:16 PMprivate val myMap = mutableMapOf<String, Long>()
private fun defaultValue(): Long = 5
fun get(key: String) {
myMap.getOrPut(key, ::defaultValue)
}
Andreas Sinz
02/28/2017, 12:17 PMnorth
02/28/2017, 12:18 PMAndreas Sinz
02/28/2017, 12:18 PMnorth
02/28/2017, 12:19 PM<kotlin.version>1.0.6</kotlin.version>
north
02/28/2017, 12:20 PMAndreas Sinz
02/28/2017, 12:20 PMdefaultValue()
as a static method, which is not possible. and references to instance-methods are not supported in 1.0.6, you'd need 1.1 for thatnorth
02/28/2017, 12:20 PMAndreas Sinz
02/28/2017, 12:20 PMmyMap.getOrPut(key, { defaultValue() })
north
02/28/2017, 12:21 PMnorth
02/28/2017, 12:21 PMAndreas Sinz
02/28/2017, 12:22 PMmyMap.getOrPut(key, this::defaultValue)
north
02/28/2017, 12:22 PMnorth
02/28/2017, 12:35 PM