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

Alexander Suraphel

11/01/2021, 2:12 PM
What is
R
supposed to be set by default on this snippet?
c

Casey Brooks

11/01/2021, 2:19 PM
Yeah, the documentation is a bit confusing for delegates.
thisRef
will refer to the object that contains the delegate, which would be an instance of class
D
in your snippet. Delegates can also be used on local or top-level properties, at which point it doesn't have a "containing object" to refer to and will be the
Nothing
type
🙏 2
a

Alexander Suraphel

11/01/2021, 2:22 PM
That’s right! I just figured it out. What’s not clear to me is how the semantics EffectiveDate() works without doing EffectiveDate<D>() @Casey Brooks
c

Casey Brooks

11/01/2021, 2:42 PM
Compiler magic basically 😉. The
R
type will always refer to the type of class it's contained in (or
Nothing
). So the compiler sees that you're calling
EffectiveDate()
and assigning it to a member property within class
D
, so that becomes the
R
type
😉 1
2 Views