I think you might have been misled by the unfortunate mixing of
concepts in the discussion, so I understand you would question this.

DELEGATES
For events, C# uses delegates which are type-safe method handles.
Normal delegates are strong references, much like in Java, so the
listeners will only become candidates for GC when they are
unregistered OR the observable itself is subject to GC. This is no
different than maintaining a manual list of observers in Java except
it's baked in with some handy syntax (you invoke the delegate itself,
isolated from the knowledge of the target object(s)). So if you can
attain signature compatibility, you can wire things together.
Delegates supports multi-casting, where you can add compatible
delegates to another delegate. Silly example:

// Multicast (void) delegate which can call anything that takes a
string
public delegate void FeedbackDelegate(string s);

// Rather than mess with interface and adaptor class, create a
delegate and associate with a SL4J logger instance's info method.
FeedbackDelegate feedback = new FeedbackDelegate(sl4j.info);
// In Java we can never have too many logging frameworks
feedback += new FeedbackDelegate(log4j.log);
// Let's also wire this up to a UI element
feedback += new FeedbackDelegate(statusBar.text);

// Usage
feedback("Hello");


EVENTS
Events make use of delegates to assign a particular event handler to
an object instance. You use the keyword "event" and lives under the
restriction that the signature must match foobar(object source,
EventArgs e). However this is what makes it possible to associate a
generic "button_click" method, no matter which button is clicked. That
method will use the event arguments to determine which button was
actually clicked. Of course it could be any event matching the
EventHandler signature so you are not just confined to buttons.

On 16 Sep., 18:01, Joshua Marinacci <[email protected]> wrote:
> in JavaFX you do this:
>
> Button {
>         action: function() {
>                 println("I'm doing stuff. Honest!");
>         }
>
> }
>
> the function above is actually a closure. You could also do this:
>
> function doStuff():Void {
>         println("I'm really doing stuff this time");
>
> }
>
> Button { action: doStuff }
>
> c'est facile!

Unfortunately JavaFX is immature and of no use to many of us. So in
Java we'll have to continue with interfaces and adapters, since beans-
binding was dropped.

/Casper
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to