Scala Constructor Parameters

后端 未结 2 1762
心在旅途
心在旅途 2020-12-06 16:20

What is the difference between a private var constructor parameter and a constructor parameter without val/var? Are they same in terms of scope/visibility?

Ex:

2条回答
  •  伪装坚强ぢ
    2020-12-06 16:57

    as a supplement, if your class is a case class, all of the constructor parameters will be automatically public fields.

    The compiler will complain about the private keyword if it exists, and for the parameters without val/var, no matter they are used or not in any defs, there will be public fields generated for them.

提交回复
热议问题