0

So... in Java we can call our getters and setters using the double colon operator, like this:

myMethod(MyClass::getSomeVar, MyClass::setSomeVar);

In Kotlin we can do the same for the getter:

myFunction(MyClass::someVar, MyClass::?)

How would we do this for the setter in Kotlin?

Displee
  • 670
  • 8
  • 20
  • Does this answer your question? [Getters and Setters in Kotlin](https://stackoverflow.com/questions/37906607/getters-and-setters-in-kotlin) – Spectric Oct 30 '20 at 14:13
  • I doubt there's a way to use the `::` syntax for that. Just use a lambda – al3c Oct 30 '20 at 14:14
  • 3
    The `::` is called a method reference. For properties you do `MyClass::p.setter` and `MyClass::p.getter`. This was already answered at [Method reference to property setter](https://stackoverflow.com/questions/43933370/method-reference-to-property-setter) – Nicolas Oct 30 '20 at 14:17
  • This question has already been asked. https://stackoverflow.com/questions/32598320/kotlin-method-reference-not-working – flopshot Oct 30 '20 at 14:19
  • Oh wauw. That setter reference worked. Thanks! – Displee Oct 30 '20 at 14:20
  • Or just `MyClass::someVar::set` – mrlem Jan 27 '21 at 16:32

0 Answers0