The problem is that case class
is more flexible than a Java record.
This can’t be expressed:
final case class Point(x: Int, y: Int) {
// No extra vals or lazy vals in records
val toTuple = (x, y)
}
Of course, Scala could compile to record
, and fallback to regular classes in case the features are not supported. But adding an initialized val
to a case class should not break binary compatibility. And historically, Scala had plenty of issues with encoding traits as interfaces, and this smells like the same thing.
Therefore, I’d be happy with @record
, especially if it throws errors if the definition becomes incompatible (like @tailrec
). But yes, please add support for Java’s records