質問

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; }
}
役に立ちましたか?

解決

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;
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top