2
  class NodeL(a :Int){
    var value = a
  }

  def change(x :NodeL) = {
    if(x == null) x = new Node
  }

when I use code above ,compiler give me an error "reassignment to val" in the statement "if(x == null) x = new Node" why?

yao liu
  • 33
  • 3

1 Answers1

5

You can't, method parameters are immutable in scala (i.e., they are vals)

Raphael Roth
  • 26,751
  • 15
  • 88
  • 145