is it possible to change the parameter name when u...
# getting-started
m
is it possible to change the parameter name when using
with(...) { }
? It was error-free until I changed it to
Copy code
with(...) { sf -> ... }
and now IntelliJ says
Expected no parameters
m
the parameter becomes
this
(the "receiver") -- you cannot change that name
👍 1
m
Good to know... then in that case, if I am using
with
within the scope of an
apply
block, is there a way to specify which
this
I'm referring to?
m
this@apply
and
this@with
let you identify the particular
this
that you want
m
Okay, I'll give those a shot. The suggestions IntelliJ was giving me for
@
labels weren't valid 😛
That worked! Thanks again Mark!
d
The way to go here is to just use a
val
(that's how you give a name to things). imho
m
Alternatively, use
also
rather than
apply
and you can rename
it
. Of course it does mean that everything now has to reference a variable name for the
apply/also
receiver.