https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Alexander Suraphel

10/29/2021, 11:42 AM
Why do delegate class methods
getValue
and
setValue
need to marked with
operator
keyword?
h

henrikhorbovyi

10/29/2021, 2:00 PM
to be accessed like:
Copy code
val message: String by delegate
a

Alexander Suraphel

10/29/2021, 2:02 PM
I thought so! But I don’t see anywhere in the doc that
by
is an operator, just a soft keyword
h

henrikhorbovyi

10/29/2021, 2:04 PM
yeah 🤔 actually
by
can be used on simple classes too https://kotlinlang.org/docs/delegation.html
a

Alexander Suraphel

10/29/2021, 2:07 PM
Yeah your link mentions
by
as clause not an operator, right?
👍 1
h

henrikhorbovyi

10/29/2021, 2:11 PM
image.png
and in observable delegate, setValue and getValue are not operators
so, idk 😄
👍 1
a

Alexander Suraphel

10/29/2021, 2:16 PM
Actually
ReadWriteProperty
which
ObservableProperty
inherits from defines them as `operator`s 🙂
h

henrikhorbovyi

10/29/2021, 2:17 PM
yeah, that's true blob thinking upside down
a

Alexander Suraphel

10/29/2021, 2:24 PM
I’ve created a StackOverflow question just in case.
@henrikhorbovyi someone answered the question perfectly on SO. You might want to check it out.
h

henrikhorbovyi

10/29/2021, 2:51 PM
ooh... cool
a

andylamax

10/30/2021, 2:29 AM
by is an operator. It operates on getValue and setValue. If the docs is missing that, then its something that has to be added
5 Views