In Scala, how do you define a local parameter in the primary constructor of a class?

后端 未结 4 2058
走了就别回头了
走了就别回头了 2020-12-16 22:32

In Scala, how does one define a local parameter in the primary constructor of a class that is not a data member and that, for example, serves only to initialize a data membe

4条回答
  •  清酒与你
    2020-12-16 22:37

    You can create temporary variables throughout the initialization of single class members like this:

    class A(b:Int){
      val m = {
        val tmp = b*b
        tmp+tmp
      }
    }
    

提交回复
热议问题