Extension functions apparently can't be JvmStatic....
# getting-started
s
Extension functions apparently can't be JvmStatic... What can I do to improve the API for Java users here? https://github.com/Ashampoo/kim/blob/49b7f3abdbc7d5ab58e09255282a80e7e983285b/src/jvmMain/kotlin/com/ashampoo/kim/JvmKimExtensions.kt#L33 Without that available it's not very nice to use: https://github.com/Ashampoo/kim/blob/examples/examples/kim-java-sample/src/main/java/Main.java
JvmKimExtensionsKt
itself is available, but this looks strange and I don't want to showcase that. What are my alternative options to make a
Kim.readMetadata(file)
work in Java?
e
@file:JvmName
which is an ABI-incompatible change of course
s
Thanks, will try that. As long as Kim is not a 1.x release I think I'm free to break sometimes 😄
Oh, that's an
JvmKimExtensions.kt:27:5 Unresolved reference: Kim
Because there is already a
Kim.kt
at https://github.com/Ashampoo/kim/blob/main/src/commonMain/kotlin/com/ashampoo/kim/Kim.kt
That Kim object is the central API to use the lib. in commonMain is takes parameters valid for all platforms and in specific source set it extents
In Kotlin code im import the extension function and it looks like it should. In Java code it's not so easy
Maybe I need to extract the common logic elsewhere and provide each platform with their very own Kim object, but I hope that there is an easier solution
h
Never used it but you could try JvmMultifileClass: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-multifile-class/ To merge it with the existing Kim file
e
only works if everything is also a top-level file and not an
object
h
But you already have an object, so why not add the function to Kim?
s
Ok, understood. I think I create platform-specific Kim objects. Thank you 🙂
e
I don't think you want to do that. that will make it difficult to use Kim in common sourcesets
h
You can also add a JVM only function by hiding it from Kotlin
s
How?
h
Deprecated.Hidden
s
I look that up.
I don't think you want to do that. that will make it difficult to use Kim in common sourcesets
Good point.
@Deprecated(HIDDEN)
feels a bit wrong/hacky. It seems to be intended for libraries that are in the process of Kotlin migration.