Common function in Vala

I wrote maximum () common function in Val. However, it does not compile. There he is:

T maximum<T>(T a, T b) {
    return a > b ? a : b;
}

void main() {
    stdout.printf("%d\n", maximum(10, 2));
}

I got the following error:

generics.vala:2.12-2.16: error: Relational operation not supported for types `T' and `T'

Do you know how I can fix this function so that it can be compiled? Thank.

+5
source share
1 answer

General direct comparisons and various other operations are not supported by the current Vala. You can use and implement the Gee.Comparable interface to use the compare_to () method.

+5
source

All Articles