Hi Will and thanks for using Gosu!
We do not currently support the volatile keyword for fields of a Gosu class. However we will look into adding it.
I'm not sure about your use case, but for an alternative way to have control over how an instance variable is initialized you might consider gw.util.concurrent.LockingLazyVar<T>
.uses gw.util.concurrent.LockingLazyVar
class Foo {
var _bar = new LockingLazyVar<Integer>() {
override function init() : Integer {
print("initializing _bar")
return 2 + 2 //or do more complex initialization here
}
}
property get Bar() : Integer {
print("getting Bar")
return _bar.get()
}
}
Then simply new up Foo and call its Bar property from a Program:
getting Bar
initializing _bar
4
Note that the init() method is called after the getter is first accessed.
Again, I know this may not satisfy your use case but hopefully this can help.
- Kyle