What is the advantage of these kind of parameterization?
I can think of two possible advantages:
- Delayed construction.
You can construct part of the instance in one area of the code base...
val almostA = new A(10, 20)(_)
...and complete it in a different area of the code.
val realA = almostA(30)
- Default parameter value.
Your example doesn't do this, but a curried parameter can reference an earlier parameter.
class A (a:Int,b:Int)(c:Int = a){ . . .
When I create an object as val obj = new A(10,20) I am getting runtime error.
You should be getting a compile-time error. You either have to complete the constructor parameters, new A(10,20)(30), or you have to leave a placeholder, new A(10,20)(_). You can leave the 2nd parameter group off only if it has a default value (see #2 above).
aandbbut don't yet knowc, it may be beneficial to partially-build an instance ofA, that can be given to something that can finish the job