1

I´m following the Udacity course to learn how to develop android apps, and I don´t understand the following piece of code:

 private val night = MediatorLiveData<SleepNight>()
    fun getNight() = night

    init {
        night.addSource(database.getNightWithId(sleepNightKey), night::setValue)
    }

Specifically, I don´t understand the "::" part, from some answers to this question I know that is used to transform a function into a lambda, I also checked the official docs and says that is used to create a member reference and a class reference, I think in this case it is used to create a member reference but I don´t clearly see how that works in this case.

1 Answers1

2

In this context it is bound function reference - see https://kotlinlang.org/docs/reflection.html#bound-function-and-property-references for details.

It basically means a reference to a method setValue but called on the object night (night is its receiver).

night::setValue <=> { night.setValue() }

Eduard Tomek
  • 344
  • 1
  • 7