Sami Eljabali
03/31/2021, 11:00 PMIntents.kt
@file:JvmName("IntentsUtil")
@file:JvmMultifileClass
open class Intents {
companion object
}
PlayStoreIntents.kt
@file:JvmName("IntentsUtil")
@file:JvmMultifileClass
fun Intents.Companion.viewAppOnPlayStore(appUri: String): Intent =
Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(appUri)
setPackage(Apps.PLAY_STORE.url)
}
When invoked Java side was able to simply:
IntentsUtil.viewAppOnPlayStore("foo");
Now however, it requires me to do:
IntentsUtil.viewAppOnPlayStore(Intents.Companion, "foo");
Any idea to why that is? How can I avoid passing the Companion object?nanodeath
03/31/2021, 11:06 PMSami Eljabali
03/31/2021, 11:07 PMrnett
03/31/2021, 11:07 PMJvmMultifileClass
, but I'm guessing it doesn't play nice with companion objects. Can you make Intents
an object? Probably worth filing a bug reportSami Eljabali
03/31/2021, 11:14 PMIntentsUtil.viewAppOnPlayStore(Intents.INSTANCE, "foo");
Sami Eljabali
03/31/2021, 11:15 PMSami Eljabali
03/31/2021, 11:29 PMnanodeath
04/01/2021, 3:46 AM"1.14.2"did you mean 1.4.32?
Sami Eljabali
04/01/2021, 4:30 AMAlbert Chang
04/01/2021, 8:47 AM@JvmStatic
doesn't work on extensions. This makes sense because what if the extension is defined in a different module? I would say defining the utilities as top-level functions is a better choice.Sami Eljabali
04/01/2021, 4:05 PMAlbert Chang
04/02/2021, 5:16 AMIntents
class is in module A, the compiled java class Intents.class
is also in module A. Then you add an extension for Intents.Companion
in module B, but it is impossible to insert the method into Intent.class
which is compiled in module A.Sami Eljabali
04/02/2021, 5:46 AMAlbert Chang
04/02/2021, 5:47 AMrnett
04/02/2021, 6:23 AMJvmMultifileClass
won't work cross module. But if you're in the same module and using JvmMultifileClass
, even across multiple files (which is what it's for), there's no reason JvmStatic
wouldn't work. The whole point of JvmMultifileClass
is to allow splitting a Java class across multiple files, so it's packing non-static methods into a single classfile already; static should be possible as well.rnett
04/02/2021, 6:25 AMJvmMultifileClass
, see the example https://kotlinlang.org/docs/java-to-kotlin-interop.html#package-level-functions
I'd still think objects should be supported eventually, but idk if they are at the moment.