Subscribe

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class Subscribe(val priority: Int = Priority.NORMAL)

Marks a method as an event handler to be discovered by an EventBus.

A valid handler method must:

  • Accept exactly one parameter whose type implements Event.

  • Return Unit / void.

Handlers may be instance methods (registered via EventBus.subscribe) or static / @JvmStatic methods (registered via EventBus.subscribeStatic).

Override behaviour: if a subclass overrides a handler method without re-annotating it, the override shadows the base class handler and will not be dispatched. Always re-annotate overrides:

class Sub : Base() {
@Subscribe
override fun on(e: MyEvent) { super.on(e) }
}

Parameters

priority

Dispatch priority. Use Priority constants or any integer. Defaults to Priority.NORMAL.

Properties

Link copied to clipboard