Is it possible to refactor `fun example(f: (String...
# announcements
s
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
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
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
I dont think theres a point beyond clarity
So the callers of
f
are all inside the
example
function right.
s
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
I can't definitively answer that, but that at least clarifies your question
s
Alright. Thanks for the response 👍