Question

Is there any way to do something like the following in Vala ?

public int year {
    get { return this.year; }
    set requires (1500 < value && value < 2050) { this.year = value; }
}
Was it helpful?

Solution

No, but 'requires' is really just syntactic sugar for GLib.return_if_fail and GLib.return_val_if_fail, so you could just do:

public int year {
    get { return this.year; }
    set {
        GLib.return_if_fail (1500 < value && value < 2050);
        this.year = value;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top