Assume that we have a class constructor that takes parameters that have default value.
class A(val p1 : Int = 3, val p2 : Int = 4)
Let's say I don't have control over this class and can't modify it in anyway. What I want to do is to call A's constructor with p1 = 5, p2 = (if condition1 == true then 5 else default value). One way to do this is
if(condition1)
x = new A(5,5)
else
x = new A(5)
As you can see, this can easily get big if there are many parameters and each must be supplied conditionally. What I want is something like
x = new A(p1 = 5, p2 = <if condition1 = true then 5 else default>)
How can I do that? Note that the fields in class A are vals, so I cant change them after instantiating A.