I’m a little stumped at how silly this problem is and have a serious mindblank, but I thought I might ask anyway.
I have an object Foo, with several fields. I want a method that can change any of its fields depending on which one is passed in as a parameter. Like so:
class Foo {
var x = 0
var y = 0
}
class Bar {
def changeFooField(field : Int) = {
field = 1
}
}
Can I not use it like so?:
changeFooField(foo.x)
If not, how do I accomplish this?
No you cannot. You’ll need to enclose the field value into an object: