我有一个带有几个参数的类,例如class Building(val a: Int, val b: Int, val c: Int)
. 我必须更新的这段代码是这样的:
def updatedA(a: Int): Building = new Building(a, this.b, this.c)
def updatedB(b: Int): Building = new Building(this.a, b, this.c)
有没有更短的方法来获取更新的对象,如下所示?
def updatedA(newA: Int): Building = new { val a = newA } extends this // doesn't compile/ type is AnyRef instead of Building