In scala swing I can do something like the following:
val field = new TextField("", 4)
field.text = "Hello"
And the assignment is implemented thus:
def text_=(t: String): Unit = peer.setText(t)
But if I try my own implementation such as:
case class A(i: Int) {
def value_=(j: Int) = copy(i = j)
}
val a = A(3)
a.value = 3
This will not compile for me. What am I missing?
In Scala 2.13 (and 3) the setter
def value_=
(ordef value_$eq
) seems to work if you declare a fieldvalue
or
By the way, it's a little confusing that a setter
value_=
returnsA
rather thanUnit
In Scala 2.12 the "setter"
def value_=
(ordef value_$eq
) works if you declare a "getter" too