I have a class like this:
class A(arg: Int)(implicit i: Boolean) {
def apply(v: Double): this.type = {
// do stuff
this
}
}
and I want to instantiate it by doing initialization and calling on the same line:
implicit val i = false
val a = A(arg=1)(v=2.0)
val a2 = (A(arg=1))(v=2.0)
Unfortunately, the compiler assumes that v = 2.0 is for the implicit parameter, not for apply (). I tried several different syntax with insert {} and (), but none of them worked. I understand that v can be moved to the constructor, but in my case this is not an option, because A is subclassed, and I do not want to add v to each constructor of the subclass. Is there any way to achieve this? Thank.
source
share