Is there a difference between it and this in kotli...
# announcements
m
Is there a difference between it and this in kotlin? If so, why do different scoping functions use one but not the other?
g
this
is always current scope
it
is just a default name of parameter in lambda with only one param. So you can omit name for such case and use
it
instead, but if you set name for lambda parameter explicitly, you don’t have access to
it
anymore. See documentation about lambdas and
it
https://kotlinlang.org/docs/reference/lambdas.html#it-implicit-name-of-a-single-parameter
why do different scoping functions use one but not the other
So answering on your question. Some scope functions use receiver as scope, some just pass it as lambda parameter
m
oh right... that makes sense. Thanks!