我有以下方法,我正在寻找一个2D矢量中的字符的位置。斯卡拉 - 块不能包含声明
def findChar(c: Char, levelVector: Vector[Vector[Char]]): Pos = {
var pos: Pos
pos.x = levelVector.indexWhere(row => row.indexOf(c) > 0)
pos.y = levelVector(pos.x).indexOf(c)
pos
}
pos
具有记得在X和Y轴的位置
然而,上线var pos: Pos
我收到错误Block cannot contain declarations
两个整型字段。
为什么块不能包含声明? 这是我的代码问题?
你能添加堆栈跟踪吗?类Pos定义也是如此 –