This page is no longer maintained — Please continue to the home page at www.scala-lang.org

ListBuffer.++, and List.+

1 reply
ounos
Joined: 2008-12-29,
User offline. Last seen 3 years 44 weeks ago.

I think this should be made to work:

val x = new ListBuffer[Int]
x += 1
x ++ x

Now it throws an OOME.

Also, when I try this:
val x = List(1)
x += 2

I get a compiler error "reassignment to val".
But there is no "+=" method defined in list, only "+". Does the compiler
treat "x += y", when there is no x.+= method, as "x = x + y"?

Thanks,
Dimitris

Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: ListBuffer.++, and List.+
Yes, the compiler does that.

2009/1/10 Dimitris Andreou <jim.andreou@gmail.com>
I think this should be made to work:

val x = new ListBuffer[Int]
x += 1
x ++ x

Now it throws an OOME.

Also, when I try this:
val x = List(1)
x += 2

I get a compiler error "reassignment to val".
But there is no "+=" method defined in list, only "+". Does the compiler treat "x += y", when there is no x.+= method, as "x = x + y"?

Thanks,
Dimitris



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland