Re: [Vala] Is there any way to access generic type from the interface?



​​
Right, I see what u are asking now.

Well, if you want to do Mixins in Vala, you'll have to do the "static"
workaround, since it doesn't support by default:
https://wiki.gnome.org/Projects/Vala/Tutorial#Mixins_and_Multiple_Inheritanae

Now you want to do Mixing with Generics? Ok, add the generic argument to
each  Mixin method of your interface:

​public interface IMixinInterface : Object {
    public abstract void foo();

    public static T default_fooing<T>(T arg) {
        GLib.message("fooed defaulty!");
        return arg;
    }
}

public abstract class BaseFooer : Object, IMixinInterface {
    public virtual void foo() {
        var dummy_string = IMixinInterface.default_fooing<string>("dummy
string");
        GLib.message(dummy_string);
    }
}

public class NothingSpecialFooer : BaseFooer {
}

public class TheSpecialFooer : BaseFooer {
    public override void foo() {
        GLib.message("fooed specially!");
    }
}

int main () {

    var fooer = new NothingSpecialFooer();
    fooer.foo();

    var fooer2 = new TheSpecialFooer();
    fooer2.foo();

    return 0;
}​


​This example doesn't cover BaseFooer taking a generic argument, if the
example is not enough, please​ provide me more details about how is the
generic argument used in BaseFooer.

- Fanl


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