Let's say for instance that I have the following classes, is there a way to do the copy command without overriding the argument from the superclass?
I want to avoid override val arg1: String from the declaration of - case class MyCaseClass(override val arg1: String, arg2: String) extends MyAbstractClass
abstract class MyAbstractClass (val arg1: String = "bar 1")
case class MyCaseClass(arg2: String) extends MyAbstractClass
object MyMain {
def main(args: Array[String]): Unit = {
val myObj = MyCaseClass(arg2 = "bar 2")
println("a.arg1: " + myObj.arg1) // a.arg1: bar 1
println("a.arg2: " + myObj.arg2) // a.arg2: bar 2
val b = myObj.copy(arg1 = "try_1", arg2 = "try_2")
//>> "too many arguments (2) for method copy: (arg2: String)com.MyCaseClass
//>> Note that 'arg1' is not a parameter name of the invoked method."
}
}
Edit: In my actual code I got hundreds of fields, that's why it's so important, I want to keep clean code and avoid hundreds of meaningless redundant overrides.
As @Mateusz Kubuszok suggested, that's might be the only option, which obviously doesn't make the code cleaner.