greenrobot / EventBus

Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.
http://greenrobot.org/eventbus/
Apache License 2.0
24.67k stars 4.66k forks source link

Does it work with Any ? #694

Closed jimlyas closed 2 years ago

jimlyas commented 2 years ago

So I would like to make a general function to subscribe to any event, because my component might subscribe to more than one event.

Does this work with EventBus?

@Subscribe(threadMode = ThreadMode.BACKGROUND)
fun subscribeToAnything(event : Any) {
     when(event) {
           is EventA -> // do something for event A
           is EventB -> // do something for event B
     }
}

Thanks in advance.

greenrobot-team commented 2 years ago

To subscribe to more than one event, add a @Subscribe function for each event instead.