Why can't the first parameter list of a class be implicit?

前端 未结 2 1097
无人共我
无人共我 2020-12-15 19:39
scala> class A(implicit a: Int);
defined class A

scala> class B()(implicit a: Int);
defined class B

scala> new A()(1)
res1: A = A@159d450

scala> new B         


        
2条回答
  •  抹茶落季
    2020-12-15 20:12

    The way I see it is that implicit parameter list does not replace the regular one(s). Since for constructor definitions at least one parameter list is needed, if nothing is indicated explicitly '()' is generated.

    While this might be indeed puzzling, it's in line with generating an empty constructor when no parameter lists at all are present.

提交回复
热议问题