I have the following variable and getter / setter defined in my data model:
class Actor {
int _x;
int get x => _x;
set x(int value) => _x = value;
}
And there is this generic class that requires a getter / setter function pointer
class PropertyItem {
var getterFunction;
var setterFunction;
PropertyItem(this.getterFunction, this.setterFunction);
}
How do i pass a reference of the getter / setter function of X to the PropertyItem class?
// Something like this
var item = new PropertyItem(x.getter, x.setter);
EDIT: Updated with a more clear question
In short, you don’t.
Getters and setters are not extractable – they are indistinguishable from just having a field (if you don’t do side-effects, of course).
In your example, you could just do:
and get exactly the same effect.
What you want is, for some Actor “actor”, to make the functions yourself:
This proposal about generalized tear offs is approved and will probably implemented soon and allows to closurize getters and setters like: