Re: [Vala] How do you get from the generic, to the.....specific?



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]