Re: [Vala] Generics: constraints and 'new T ()' on type parameters?



2009-02-27 Sam Danielson <samdanielson gmail com>:
[...] Ideally I would think a Factory <T>
should be able to return new T's but I can't figure out how to do
this. [...]

Hello,

as far as I know, the Vala compiler performs type erasure for generic
types. This means that the concrete type represented by T is known
neither during the compilation of the class with the type parameter
nor during runtime. Hence it is impossible to instantiate an object of
type T.

However, nothing prevents you from passing runtime type information
around yourself: If your Factory class has access to a GLib.Type
handle it should be able to create an instance of that type
reflectively.

cu,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]