I'm using value class in Scala to avoid boxing at runtime.
Eg.:
trait Service {
def getThing(thingId: ThingId): Thing
}
final case class ThingId(value: Long) extends AnyVal
However, I'm using that same value class from Java code:
interface JavaService {
Thing getThing(ThingId thingId);
}
This does not work since ThingId
is actually compiled as a Long:
JavaService.java:[2,19] error:
incompatible types: ThingId cannot be converted to long
Is there a pattern to use value classes (or any wrapper/helper that would help) from Java?