How do I expose Scala constructor arguments as public members?

前端 未结 2 791

Look at this example:

class Point(x: Double, y: Double){
  override def toString = \"x: \" + x + \", y: \" + y
  def +(sourcePoint: Point) : Point = {
    re         


        
2条回答
  •  独厮守ぢ
    2020-12-17 08:05

    using val is valid but then the parameter becomes final (constant). If you want to be able to reassign the value you should use var instead. So

    class Point(var x: Int, var y: Int)
    

提交回复
热议问题