Re: getter / setter questions

View: New views
1 Messages — Rating Filter:   Alert me  

Re: getter / setter questions

by Naftoli Gugenheim :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is your question that it seems to be an arbitrary rule, or do you have a case where it would be helpful to have a separate name? The point of _= is that it should act like a var which is read/write.

-------------------------------------
Micha<micha-1@...> wrote:

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