I have such Kotlin entity
value class EntityId(val id: Long) {}
and some service's interface
interface Service {
fun do(entityId: EntityId)
}
and its implementation.
But when I use the interface from Java code like this
{
...
EntityId id = new EntityId(1L);
service.do(id) // service is interface here
}
I receive the compilation error. But it's pretty understandable behaviour because Kotlin compiler generates fun do(entityId: Long) from the sources.
Okay, let use something like this service.do(1L).
Another issue will occur:
java: cannot find symbol
symbol: method do(long)
I guess it occurs because interface actually isn't changed during compilation. I found a single way - replace value class with data class but I would have value class.
Maybe, does some workaround exist for such a case?
You could overload the function that takes
value classwith a function that takesLongand calls the original under the hood.Kotlin
Then you can call it from Java with a
Longliteral: