Re: [Vala] Delegate that returns its own type



Zsolt Börcsök schrieb:
If not, do you have any suggestion to replace this kind of declaration.

As a workaround you could code your own delegates with the classic strategy pattern:

-------------

using GLib;

private interface MyDelegate {
        public abstract MyDelegate call ();
}

private class MyDelegateImpl : Object, MyDelegate {
        public MyDelegate call () {
                return new MyDelegateImpl ();
        }
}

public class DelegateTest {

        private static void wants_delegate (MyDelegate deleg) {
                MyDelegate result = deleg.call ();
        }

        public static int main (string[] args) {
                MyDelegate deleg1 = new MyDelegateImpl ();
                MyDelegate deleg2 = deleg1.call ();
                wants_delegate (deleg2);
                return 0;
        }
}

-------------

The delegate implementations have to be outside since Vala doesn't seem to support anonymous inner classes like Java.


Regards,

Frederik



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