subscribeStatic

abstract fun subscribeStatic(klass: Class<*>)

Registers all static methods on klass annotated with @Subscribe.

"Static" means:

  • Java: static methods.

  • Kotlin: methods annotated with @JvmStatic inside a companion object or object.

Kotlin object caveat: plain (non-@JvmStatic) methods on a Kotlin object are compiled as instance methods on the singleton, not static methods. They will not be found by subscribeStatic. Either annotate them with @JvmStatic, or pass the singleton instance to subscribe instead:

object MyListener {
@JvmStatic @Subscribe // found by subscribeStatic
fun onA(e: EventA) { }

@Subscribe // found by subscribe(MyListener)
fun onB(e: EventB) { }
}

bus.subscribeStatic(MyListener::class.java) // picks up onA
bus.subscribe(MyListener) // picks up onB