« Return to Thread: getter / setter questions

Re: getter / setter questions

by Michael Wohlwend :: Rate this Message:

Reply to Author | View in Thread

Am Wednesday 08 July 2009 01:36:38 schrieb Daniel Sobral:
> Now, while this would be easy to do if Scala was the only user code, it has
> to interface with Java as well. In Java, methods and fields are
> syntactically different, so any change from one to the other would break
> Java client code.
>
> Therefore, what Scala actually does when you declare "var v" is to compile
> that into a v field, a v() method, and a v_= method.
> Which is why you can't both declare "var v" and "def v". It's the same
> namespace.

no problem with that. I was wondering why the setter has to have the same name
as the getter, which isn't obvious for me, you even don't need an associated
field to set. But the compatibility to java seams the reason.



thanks
 Michael

 « Return to Thread: getter / setter questions