class constructor with implicit parameters
implicit parameter list
- Implicit applies to the whole list of arguments after it. Normal parameters and implicit parameters cannot be mixed in a single parameter list.
- A method can only have one implicit parameter list and the list has to be the last one.
- Auxiliary constructor must have a non-implicit parameter list.
// error, cannot mix non-implicit and implicit together
class Test1(a: Int, implicit b: Int)
// correct, implicit list is the last list
class Test2(a: Int)(implicit b: Int)
// correct, mix with non-implicit with implicit val
// implicit actually is defined on the b() method
class Test3(a: Int, implicit val b: Int)
class Test4(a: Int)(implicit b: Int) {
// error, auxiliary constructor must have one non-implicit parameter
def this(implicit b: Int) {
this(3)(b)
}
}
class Test5(a: Int)(implicit b: Int) {
// correct, auxiliary constructor with an empty non-implicit parameter
def this()(implicit b: Int) {
this(3)(b)
}
}