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

simon.vergauwen

06/24/2019, 11:05 PM
Is it possible to refactor
fun example(f: (String) -> Unit): Unit
into
fun example(f: (stringParam: String) -> Unit): Unit
and refactor all usages of the lambda to use that name in my project?
d

Dico

06/25/2019, 3:43 PM
Extremely unlikely. The parameter name isn't relevant to the code calling
example
. I believe it is also not retained in binaries at all.
The interface
KFunction1
declares the parameter name, it can therefore not technically be different. Parameter names of lambda types might be a future feature, perhaps.
Then the question is, what do you mean by usages? Callers of
example
or
f
s

simon.vergauwen

06/25/2019, 3:46 PM
I thought it was retained in metadata and read from IntelliJ to suggest param names.
I mean the callers of
f
, the reason I want to do this is to improve readability of library code. If I have to do it manually I probably still will but it'll suck
If there is another way to achieve the same goal that'd be as good but if so is there a point in naming lambda params from a library point of view?
d

Dico

06/25/2019, 5:42 PM
I dont think theres a point beyond clarity
So the callers of
f
are all inside the
example
function right.
s

simon.vergauwen

06/25/2019, 6:03 PM
Oh doy. Of course I meant callers of
example
so whoever defines parameter names for the lambda. I want
example { s ->}
to become
example { stringParam ->}
in my code after the refactor.
I dont think theres a point beyond clarity
So no point for a library to do this? Or will IDEA still suggest the param name based on the Metadata?
d

Dico

06/25/2019, 6:22 PM
I can't definitively answer that, but that at least clarifies your question
s

simon.vergauwen

06/25/2019, 6:25 PM
Alright. Thanks for the response 👍
3 Views