<@U0D06TWMA> ``` private val myMap = mutableMa...
# getting-started
n
@Andreas Sinz
Copy code
private val myMap = mutableMapOf<String, Long>()
    private fun defaultValue(): Long = 5
    fun get(key: String) {
        myMap.getOrPut(key, ::defaultValue)
    }
a
north: is this code inside a class?
n
yes
a
are you running kotlin 1.1 or 1.0.6?
n
<kotlin.version>1.0.6</kotlin.version>
does this get better with kotlin 1.1?
a
ok, so what you are basically trying to do is use the Instance-method
defaultValue()
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 that
n
I see
a
easiest way to work around it is to use
myMap.getOrPut(key, { defaultValue() })
n
nice... thank you
looking forward to 1.1
a
with 1.1 you can go with
myMap.getOrPut(key, this::defaultValue)
n
that's what I first tried to fix it in 1.0.6 🙂
One last question on this topic. If I wanted to reference a function in 1.0.6 would it need to be defined at top level or in a closure? (so basically not an instance method from a class/object)