If I need to pass the current JVM class to a stati...
# announcements
e
If I need to pass the current JVM class to a static method but I don't really have a class, is this the only way to do it? See image.
k
It there a specific reason for why you want your icons to be accessible on top-level? If not, maybe using an
object
could solve this problem and keep the top-level domain from being polluted.
e
@kralli not really a reason tbh. It's that I started that way and... we are here đŸ˜…
k
Copy code
object CCIcons {

    @JvmField val ICON = getIcon("/test.svg", CCIcons::class.java)
}
e
@kralli and I cannot change it as I have external dependencies on those.
@kralli yep! That would be the correct refactoring, but maybe there is a way to avoid it
k
So you’re using the top-level variables from Kotlin in a different module?
Or only from Java?
e
@kralli to be specific, that code comes from an IntelliJ plugin. And I have other plugins depending on those top level definitions (both Java and Kotlin)
@kralli maybe I'm lucky. Since I have named that JVM file
CCIcons
I can refactor as you showed without losing binary compatibility.
k
That’s why I brought it up, though this does only apply to binary compatibility. In Kotlin it will obviously make a difference.
so no source code compatibility in Kotlin
e
@kralli that's fine. I'll give this a try! Thanks!