https://kotlinlang.org logo
#compiler
Title
# compiler
n

natario1

01/26/2023, 12:44 PM
Not sure if this is the best channel to ask, but do Kotlin lambdas not exist as a runtime interface? For example,
Class.forName("kotlin.Function0")
fails. And is there a way to have them exist? Maybe some compiler flag? I want to call the invoke function from JNI.
d

dmitriy.novozhilov

01/26/2023, 12:47 PM
kotlin.Function
and
kotlin.coroutines.SuspendFunction
are not exists at runtime On JVM they are mapped to
kotlin.jvm.functions.FunctionN
n

natario1

01/27/2023, 10:25 AM
I see, thanks. I wasn’t able to make it work for suspend functions, finally I found out it’s mapped to
kotlin.jvm.functions.Function(N+1)
. For the continuation I guess
Btw it would be nice if these things were handled by
org.jetbrains.kotlin.resolve.jvm.JvmClassName
. For lambdas but also more common things like kotlin/String, kotlin/Any (should be java/lang) which are hardly useful
d

dmitriy.novozhilov

01/27/2023, 10:36 AM
What do you mean? java.lang mappings exist only during compilation on jvm. In js and native there are actual kotlin. classes
n

natario1

01/27/2023, 10:41 AM
I mean, as a plugin author, I am using
JvmClassName
to get a JVM friendly name, with
/
,
$
and so on. I was saying that it would be nice if
JvmClassName
also did the string conversion between impossible types like kotlin/Any => java/lang/Object and more delicate ones like suspend functions
d

dmitriy.novozhilov

01/27/2023, 2:59 PM
Well,
JvmClassName
is an internal utility which does what it does If you want to map kotlin classes to java runtime you can use `KotlinTypeMapper`/`IrTypeMapper`
u

udalov

01/31/2023, 12:39 PM
You can also use
JavaToKotlinClassMap
just for the class name mapping logic
n

natario1

01/31/2023, 2:59 PM
Looks promising, thanks!
4 Views