Hello,

2010/1/20, Michael 'Mickey' Lauer <[email protected]>:
> 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
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to