We have two projects, and the kotlin one publishes a package that's imported by java.
In kotlin, is a value class like
@JvmInline
value class CountryId(private val id: UUID) {
override fun toString(): String = id.toString()
companion object { fun empty(): CountryId = CountryId(EMPTY_UUID) }
}
In java, we can't see a constructor, or actually instantiate this class. I have also tried creating a factory in Kotlin to create them
class IdentifierFactory
{
companion object {
fun buildString(): String {
return "hello"
}
fun buildCountry(): CountryId {
return CountryId.empty()
}
}
}
In java, I can call IdentifierFactory.Companion.buildString()
and it will work, but IdentifierFactory.Companion.buildCountry()
doesn't even exist.
Is Java really this awful with Value classes?
ps. I've attempted with @JvmStatic as well, with no success
pps. If I decompile the kotlin bytecode from the java side, and get a CountryId.decompiled.java, this is what the constructor looks like
// $FF: synthetic method
private CountryId(UUID id) {
Intrinsics.checkNotNullParameter(id, "id");
super();
this.id = id;
}
ppps. Kotlin 1.5.21 and Java 12
@JvmName
to customize the Java method name – ApparentCountryId
constructor works fine for me from Java. What do you mean it doesn't work for you? – Apparentsrc/main/kotlin
andsrc/main/java
respectively). – Apparent