With Kotlin JvmStatic is for JVM static functions. Specifically, in a companion object in a class, can I use @JvmStatic with a thing not necessarily on JVM?
I have tried researching everywhere, no luck. I may try Kotlin playground next. My current development machine is a tablet so I can't just compile. I was expecting this to be documented somewhere.
I tried Kotlin playground, error unless JVM, but still unsure if it would work like building. I expect code to be able to run in multiplatform but not be affected by that annotation.
Unsure if multiplatform, which is like my target, compiles correctly for non-JVM with @JvmStatic annotation. Specifically, multiplatform library, all supported platforms.
The @JvmStatic annotation is meant to affect how Kotlin code is compiled to the JVM target, so it is only useful for the JVM target. However, sometimes we write common (multiplatform) code that targets the JVM among other platforms.
This is why the JvmStatic
annotation is actually defined for Common
and JVM
- you can check that in the documentation page, which has some colored bubbles for the supported platforms: