Victor Cardona
10/28/2021, 1:48 PMpublic interface Identifier {
public val value: String
}
private val validationRegex = Regex("""^[0-9a-f]{32}$""")
@JvmInline
value class SampleIdentifier(override val value: String) : Identifier {
init {
require(validationRegex.matches(value)) {
"The value $value is not a valid SampleIdentifier"
}
}
}
class Sample(
val identifier: SampleIdentifier,
) {
}
This works wonderfully in Kotlin, but I can’t figure out how someone using Java (we still have a lot of that) could create an instance of Sample. The following code fails saying that the constructor has private access:
Sample sample = new Sample("1295f");
I’m assuming this is due to function name mangling but am not sure how to integrate it with existing Java code.
Thanks!