Re: [Vala] How do you get from the generic, to the.....specific?
- From: Matto Marjanovic <maddog mir com>
- To: vala-list gnome org
- Subject: Re: [Vala] How do you get from the generic, to the.....specific?
- Date: Sat, 18 Feb 2012 20:32:58 -0800
On 02/18/12 15:10, ant wrote:
On 18 February 2012 21:56, Evan Nemerson<evan coeus-group com> wrote:
public int get_length<T> (T val) {
if ( typeof (T) == typeof (string) ) {
return ((string) val).length;
} else {
GLib.error ("Unable to handle type `%s'", typeof (T).name ());
}
}
Are there any plans to add type bounds to Vala generics?
This would allow something like (e.g., using Java's keyword):
public int get_length<T extends string> (T val) {
return val.length;
}
I.e. the T is qualified to be a subclass of 'string' (not that this is
necessarily possible in Vala), and thus the compiler knows that anything
that can be done to a string can be done to an instance of T.
-m
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]