Re: [Vala] Delegates in generic classes
- From: Abderrahim Kitouni <a kitouni gmail com>
- To: "Michael 'Mickey' Lauer" <mickey vanille-media de>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Delegates in generic classes
- Date: Wed, 20 Jan 2010 16:30:43 +0100
Hello,
2010/1/20, Michael 'Mickey' Lauer <mickey vanille-media de>:
Hi,
the attached source file fails to compile with:
foo.vala:19.34-19.46: error: Argument 1: Cannot convert from
`myIntCallback' to `GenericClass.Callback'
var gc = new GenericClass<int>( myIntCallback );
^^^^^^^^^^^^^
Apparantly, Vala does not recognize the equality of the generic
and the concrete type. Is there any way to work around that?
The workaround I see is to use a generic delegate instead of a
delegate-in-a-generic-class, still this needs an explicit cast, but it
works :
public delegate void Callback<T>( T element );
public class GenericClass<T>
{
private Callback<T> cb;
public GenericClass(Callback<T> cb)
{
this.cb = cb;
}
}
public void myIntCallback( int element )
{
message( @"$element" );
}
void main()
{
var gc = new GenericClass<int>((Callback<int>) myIntCallback);
}
HTH,
Abderrahim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]