|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ekuefler.supereventbus.multievent.MultiEvent
public class MultiEvent
An event wrapping another event that could be one of several unrelated types. This allows a handler method to handle events of multiple types that are not assignable to each other. For example, the following method would be invoked whenever Strings or Doubles were posted on the event bus:
@Subscribe void handleMultipleTypes(@EventTypes({String.class, Double.class}) MultiEvent event) { if (event instanceof String) { Window.alert("Got a string: " + event.getEvent()); } else if (event instanceof Double) { Window.alert("Got a double: " + event.getEvent()); } }Note the use of the
EventTypes
annotation to indicate which types of events should be
handled. Parameters of type MultiEvent
in Subscribe-annotated methods must always contain
this annotation.
Also note that this technique should be used relatively sparingly. Most of the time, events that should be handled in the same way should be made to extend a common base class or interface, in which case that type can be made the argument to the handler method instead of MultiEvent. MultiEvent should only be used to handle events of unrelated types that can't be made to extend a common base.
Instances of MultiEvent are created automatically by the event bus - users should never instantiate or post these events on the event bus.
Constructor Summary | |
---|---|
MultiEvent(Object event)
Instantiates a new MultiEvent wrapping the given event. |
Method Summary | |
---|---|
Object |
getEvent()
Returns the underlying event that this event wraps, which will be of a type assignable to one of the types declared in the EventTypes annotation for this parameter. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MultiEvent(Object event)
Method Detail |
---|
public Object getEvent()
EventTypes
annotation for this parameter.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |