Implementation: https://github.com/scala/scala/pull/6936
I am proposing to change the behaviour of case classes in order that the field names are shown along side the field values. For example:
case class A()
A().toString // previously: "A()", now: "A()"
case class B(i: Int)
B(1).toString // previously: "B(1)", now: "B(i=1)"
case class C(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int)
C(1,1,1,1,1,1,1).toString
// previously: C(1,1,1,1,1,1,1) .
//now: C(a=1, b=1, c=1, d=1, e=1, f=1, g=1)
For prior art, look at Kotlin’s data classes:
data class A(val a: Int, val b: String)
fun main(args : Array<String>) {
println(A(1, "hello")) // A(a=1, b=hello)
}
And Rust’s structs
#[derive(Debug)]
struct A {
a: i32, b: i32, c: i32
}
fn main() {
println!("{:?}", A { a: 1, b: 2, c: 3});
// A { a: 1, b: 2, c: 3 }
}