On Mon, 13 Nov 2006 20:06:20 -0800, Michael Torrie <[EMAIL PROTECTED]> wrote:
Observe the following two programs, both in gtk:
C#: http://www.gotmono.com/docs/gnome/bindings/gtk-sharp/buttonwidgetnormal.html (see example 2/3 way down)

If I understand what's going on in this C# program correctly,
/* Connect the "clicked" signal of the button to our callback */
button.Clicked += new EventHandler (callback);

then the corresponding Java code would look more like:
button.addListener(this);

The main difference being that in C# you can pass the method-to-be-called ("callback") directly, whereas in Java, you'd have to implement the appropriate Listener interface in order for Java to understand which method is to be called (and you'd have to name it whatever the interface wanted you to, rather than having the freedom to name it whatever you want). Also, it appears that you can pass static methods in C# as delegates, whereas in Java you'd have to create an inner class if you wanted similar functionality.

Does this sound accurate?

In any case, my guess is that Java will get delegates or something very similar quite soon. The lack of "function pointers" or "delegates" or however you want to put it has been a common nuisance of Java developers for years. Now that Java has competition in the way of C# and .NET, we've finally seen some progress in solving such annoyances.

        ~ Ross

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to