Hello! There is an Event class, it has the heirs of LoginComletedEvent , LoadingCompletedEvent and so on.

There is a listener interface with methods

  void onEventReceived(LoginComletedEvent event); void onEventReceived(LoadingCompletedEvent event); ... void onEventReceived(SomeEtcMethod event); 

How can I organize the sending of a specific event without creating a separate method for each Event heir?

Sort of :

 public <T> void post(Class<? extends Event<T>> eventClass) { for (EventListener e : listeners) { e.onEventReceived(eventClass); } } 

    1 answer 1

    For you, everything has long been invented. Eventbus

    If you want to invent the same bike yourself, then pull through the reflection the signature of all EventListener methods, and check if there is a method that takes an event of this type as a parameter.