Scala methods ending in _=

Posted by Alexey Romanov on Stack Overflow See other posts from Stack Overflow or by Alexey Romanov
Published on 2010-05-04T13:04:54Z Indexed on 2010/05/04 13:08 UTC
Read the original article Hit count: 244

Filed under:
|

I seem to remember Scala treating methods ending in _= specially, so something like this:

object X { var x: Int = 0; def y_=(n : Int) { x = n }}

X.y = 1

should call X.y_=(1). However, in 2.8.0 RC1, I get an error message:

<console>:6: error: value y is not a member of object X
       X.y = 1
         ^

Interestingly, just trying to call the method without parentheses fails as well:

scala> X.y_= 1
<console>:1: error: ';' expected but integer literal found.
       X.y_= 1
             ^

Am I misremembering something which does actually exist or did I just invent it out of whole cloth?

© Stack Overflow or respective owner

Related posts about scala

Related posts about scala-2.8