Scala 访问的内部列表的列表

Scala 访问的内部列表的列表,scala,Scala,我在scala中有以下代码位不起作用: var tacTable : List[List[TACList]] = List(List()) def gen(p: Program) = { for (i <- 0 to p.classes.length){ for (j <- 0 to p.classes(i).methods.length){ var tacInstr = new TACList() tacTable(i)(

我在scala中有以下代码位不起作用:

 var tacTable : List[List[TACList]] = List(List())

  def gen(p: Program) = {
    for (i <- 0 to p.classes.length){
      for (j <- 0 to p.classes(i).methods.length){
        var tacInstr = new TACList()
        tacTable(i)(j) = tacInstr //error: application does not take parameters
      }
    }
  }
var-tacTable:List[List[TACList]]=List(List())
def gen(p:程序)={
对于(i列表是不可变的。
请尝试以下方法:

 val tacTable  = p.classes.map { _.methods.map { _ =>
     new TACList()
 }
列表是不可变的。 请尝试以下方法:

 val tacTable  = p.classes.map { _.methods.map { _ =>
     new TACList()
 }

因为我不能在这里评论最初的帖子:

在scala for comprehension中,您可以在一个for中使用多个生成器。因此,您使用的嵌套不是必需的,因为您可以使用:

for (i <- 0 to l.length; j <- 0 to l.length) {
  // your code
}

for(i,因为我无法在此处对最初的便条发表评论:

在scala for comprehension中,您可以在一个for中使用多个生成器。因此,您使用的嵌套不是必需的,因为您可以使用:

for (i <- 0 to l.length; j <- 0 to l.length) {
  // your code
}

用于(我可以为你的问题发布一个帖子吗?可能是因为
List
是不可变的,你不能
update
它。使用
mutable.ListBuffer
或类似的东西。你能为你的问题发布一个帖子吗?可能是因为
List
是不可变的,你不能
update
它。使用
mutable.ListBuffer。)或类似的东西。