https://kotlinlang.org logo
#announcements
Title
# announcements
m

mhamade

10/25/2019, 7:03 AM
Is there a difference between it and this in kotlin? If so, why do different scoping functions use one but not the other?
g

gildor

10/25/2019, 7:13 AM
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

mhamade

10/25/2019, 7:32 AM
oh right... that makes sense. Thanks!
6 Views