« Return to Thread: getter / setter questions

getter / setter questions

by Michael Wohlwend :: Rate this Message:

Reply to Author | View in Thread

Hi,

one can define getters and setters without an associated field. But why does the
setter has to have the same name as the getter?
This compiles and works:
class X { private var v = 0; def get = v; def get_= (i:Int)  { v = i } }

This compiles and gives a runtime error:
class X { private var v = 0; def get = v; def put_= (i:Int)  { v = i } }

val k = new X
k: X = X@679e3bdd
scala> k.put = 3
<console>:6: error: value put is not a member of X
       k.put = 3


which seems not true to me :-)



thanks for answering,
 Michael



 « Return to Thread: getter / setter questions