How do you get the String companion from Java? Non...
# getting-started
h
How do you get the String companion from Java? Non native classes works well, but I am not able to get mapped Kotlin classes 🤔
e
kotlin.jvm.internal.StringCompanionObject.INSTANCE
but why do you want to get it in Java?
h
Thanks. Is it "safe" to use the
internal
package? :D I want to call some kotlin functions using the companion as a receiver like:
fun String.Companion.foo()
e
it's not a public API, but it can't change without breaking binary compatibility with existing Kotlin libraries, so… somewhat safe?
Kotlin functions defined like that aren't designed to be callable from Java though, I'd either change their definition or switch the caller to Kotlin
h
That's true, and yeah, using Kotlin is always nicer. But creating another wrapper in Kotlin is annoying too, and now knowing the companion object its usage is okay.