機能的に書き直す方法を教えてくださいtoString
。
コードは問題ありませんが、誇りに思うことは何もありません。3つの一時変数が含まれています。
class Field(x: Int, y: Int) {
val value = init(x,y)
private def init(x: Int, y: Int) = List.fill(x,y)(new Cell)
override def toString(): String = {
val temp = new StringBuilder
for(i <- value) {
for(j <- i) {
temp.append(j.toString())
}
temp.append("\n")
}
temp.mkString
}
}
みんなありがとう!