https://kotlinlang.org logo
Title
s

strelok

06/05/2017, 1:20 PM
@udalov i saw an answer to a question you provided on SO and just wanted to get some more information. It's about retaining parameter names on constructors
Was hoping you could shed some light on it for me
if you have a moment 🙂
u

udalov

06/05/2017, 1:21 PM
sure, what are you interested in?
s

strelok

06/05/2017, 1:22 PM
Thanks for such quick reply 🙂 The question I saw your answer on is here: https://stackoverflow.com/questions/36093019/does-kotlin-compiler-always-retain-parameter-names-in-bytecode it was a while ago
but to boil down the issue I am noticing in IntelliJ that the parameter names are NOT retained
at some point the parameter names are lost on a data class constructor
u

udalov

06/05/2017, 1:22 PM
how are you checking that?
s

strelok

06/05/2017, 1:23 PM
I'm stepping through the spring-data-mongodb code
and i see params being named arg0.....argXX
if I clean and re-build ... parameter names come back
then at some point (hard to pin-point when exactly) they're gone
u

udalov

06/05/2017, 1:24 PM
where do you see that — in the IntelliJ decompiler, in the
javap
bytecode output, in the Kotlin bytecode toolwindow, in Kotlin reflection, in Java reflection, … ?
s

strelok

06/05/2017, 1:25 PM
as I am stepping through the java code of spring-data-mongo...the code is looking at the constructor of a data class...I am seeing it while stepping through in IntelliJ
spring-data-mongodb code is in Java ... the class that it's looking at is in Kotlin
u

udalov

06/05/2017, 1:26 PM
OK, so the StackOverflow link above is irrelevant here because it’s only related to the parameters that are introspected via Kotlin reflection at runtime (
KParameter.name
)
here you should pass the
-java-parameters
command line argument to Kotlin
s

strelok

06/05/2017, 1:28 PM
oh ... I will read the docs on that param ... but does it force preservation of param names?
I was not aware of that option ... will try it and read the docs on it
u

udalov

06/05/2017, 1:30 PM
there’s no docs unfortunately yet, only
kotlinc -help
. The
-java-parameters
is basically equivalent to javac’s
-parameters
.
s

strelok

06/05/2017, 1:31 PM
alright I will check it out ... thanks so much for your help .... I should be able to apply it in the kotlinOptions { ... }
build.gradle
block as well, right?
u

udalov

06/05/2017, 1:32 PM
yes
s

strelok

06/05/2017, 1:34 PM
haha I just found it too ...
Generate metadata for Java 1.8 reflection on method parameters
that's good enough docs for me
Just need to know when to look! Thank you for pointing it out for me. OGROMNOE SPASIBO!