Closure | +--Multicastpublic abstract class Multicast
The Multicast class implements a multicast-enabled Closure. By inheriting from Multicast instead of Closure, a closure type can support multicasting. A Multicast descendant differs from a Closure descendant only slightly. It requires an extra statement in its implementation of the "invoke" method. An example of a Multicast subclass follows:
public final class MouseEventHandler extends Multicast { public MouseEventHandler(Object target, String methodName) { super(target, methodName); } public void invoke(int x, int y) { if (next != null) ((MouseEventHandler)next).invoke(x, y); invokeMethod(new Object[] {new Integer(x), new Integer(y)}); } }
Notice the extra statement that calls the "invoke" of the next closure if one is present. For correct invocation order to be preserved, this statement must be written BEFORE the call to "invokeMethod". Although it rarely makes sense, it is possible for closures that return function results to also be multicast. In such cases, the return value of a call to the closure's "invoke" method becomes the return value of the last method in the closure's invocation list. The return values of any methods before the last method in the invocation list are discarded. An example of a multicast closure with a function result follows:
public final class HitTestEventHandler extends Multicast { public HitTestEventHandler(Object target, String methodName) { super(target, methodName); } public boolean invoke(int x, int y) { if (next != null) ((HitTestEventHandler)next).invoke(x, y); return ((Boolean)invokeMethod(new Object[] {new Integer(x), new Integer(y)})).booleanValue(); } }
Notice that the function result of the call to "invoke" of the next closure is discarded.
Methods
Name | Description |
---|---|
getInvocationList() | Topic under construction. |
Topic under construction.