Gopal S Akshintala
07/28/2021, 4:23 AMerror: cannot find symbol
# Kotlin Value class
import io.vavr.control.Either
import io.vavr.kotlin.right
@JvmInline
value class Name(val s: String) {
val length: Int
get() = s.length
}
fun getAsName(): Either<String, Name> = right(Name("Kotlin"))
# Java Client
@Test
void testValueClass() {
final var name = getAsName().get();
Assertions.assertEquals(0, name.getLength());
}
# Error
error: cannot find symbol
Assertions.assertEquals(0, name.getLength());
^
symbol: method getLength()
location: variable name of type Name
rnett
07/28/2021, 6:06 AM@JvmName
, see https://kotlinlang.org/docs/inline-classes.html#calling-from-java-codernett
07/28/2021, 6:06 AMGopal S Akshintala
07/28/2021, 6:08 AMrnett
07/28/2021, 6:08 AM@get:JvmName
? Or @property:
?Gopal S Akshintala
07/28/2021, 6:11 AMrnett
07/28/2021, 6:13 AMGopal S Akshintala
07/28/2021, 6:15 AMfn(thisObj)
which hurts the API I am building using value classesgildor
07/29/2021, 7:35 AMgildor
07/29/2021, 7:36 AMGopal S Akshintala
07/29/2021, 8:02 AM