Hi - just read this article about the need to add ...
# compiler
r
Hi - just read this article about the need to add
@JvmSynthetic
to
internal
members to properly hide them from Java: https://medium.com/scalereal/hide-internal-members-of-kotlin-module-from-jvm-c7730507fb17 which informed me of
@JvmSynthetic
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-synthetic/ which in turn led me to
ACC_SYNTHETIC
https://docs.oracle.com/javase/specs/jvms/se15/html/jvms-4.html Is there a reason why the compiler with the JVM backend doesn’t just add the
ACC_SYNTHETIC
access_flag to
internal
methods without needing to add the noise of an extra annotation?
I suppose if you were writing a mixed Java/Kotlin module you might want to call an
internal
Kotlin member from Java… though I’ve always thought that a pretty odd thing to do.
i
The reason is simple:
synthetic
is for synthetic declarations and some tools, most notably IntelliJ debugger usually skip them. There is another way to hide Kotlin internal functions from Java, which does not affect tools so much -
@JvmName
with a dash in new name.
r
I was really hoping to avoid extra annotations. But perhaps it’s simpler to just say that anyone calling a method with
$library
at the end of the name from Java is responsible for their own pain when I rename / delete it!