given ```class Foo { class Bar { class Baz ...
# getting-started
y
given
Copy code
class Foo {
  class Bar { 
    class Baz : Bar()
  }

  fun Bar.Baz.funName() { /* ... */ }
}
this
or
this@Baz
can be used to refer to the
Baz
(and
this@Foo
is used to refer to the parent) however
this@funName
can also be used for
Baz
, what's the rationale here? that's kind of strange.
j
This situation is a bit special because your method has 2 receivers: an instance of
Foo
, because
funName
is a method of the class
Foo
, and an instance of
Baz
because
funName
declares
Baz
as a receiver. Note that the
Bar
nesting is irrelevant for this question, by the way, and so is declaring `Bar`/`Baz` inside
Foo
. It's not about the nesting of the classes, but just about referring to the correct receiver. The example works just as well when expressed this way, which might makes things clearer:
Copy code
class Foo {
    fun Baz.funName() { ... }
}

class Baz
Now, this is the same: still 2 receivers, instances of
Foo
and
Baz
. I don't know exactly why both syntaxes are allowed for
Baz
, but I imagine you can use the function name becauss this receiver is declared on the function itself (unlike
Foo
which is present for all methods of the class)
y
thanks, that's quite helpful.