[英]Cannot use primary constructor in Scala method: type "does not take parameters"
我对董事会有以下定义:
package board
import scala.collection.immutable.Vector
class Board private (values: Vector[Vector[Cell]]) {
private val cells = values
def updated(i: Int, j: Int)(newValue: Cell): Board =
this(
cells.updated(
i, cells(i).updated(j, newValue)
)
)
}
Cell
在哪里
case class Cell(value: Option[Int])
在this(
行的updated
函数内this(
我有一个错误
board.Board 不带参数
这看起来很奇怪,因为它确实如此。 为什么会这样?
PS实际上我的课程旨在更有用并包含一个公共构造函数,但上面是一个MCVE以获得相同的错误
问题是我在构造函数之外调用了this
。 我需要将其更改为new Board
:
def updated(i: Int, j: Int)(newValue: Cell): Board =
new Board(
cells.updated(
i, cells(i).updated(j, newValue)
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.