2012-02-08 30 views
5

我在Vala中編寫了最大()通用函數。 但是,它不能編譯。 這就是:Vala中的通用函數

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

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

我得到了以下錯誤:

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

你知道我怎麼能解決這個功能能夠編譯它? 謝謝。

回答

5

當前Vala不支持通用直接比較和各種其他操作。您可能想要使用和實現Gee.Comparable接口來改爲使用compare_to()方法。