EventBus
EventBus copied to clipboard
Subscriber not recognized when using extension functions
Hi, i tried to register a bus into an extension function and also hear for events into another extension function like this:
typealias SomeClass = SomeClassImpl //SomeClassImpl is a class
fun SomeClass.someExtendedFunction(){
with(someProperty){
EventBus.getDefault().register(this@someExtendedFunction) // Exception
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun SomeClass.onMessage(message:Message){
// Do something
}
The exception is:EventBusException: Subscriber class SomeClassImpl and its super classes have no public methods with the @Subscribe annotation
I suspect the issue is that extension functions are compiled to static methods, but not actual class members. The method has to be a non-static member of the class you register with EventBus, otherwise it won't be found. -ut
Thanks, you are right, i ended using it directly in the class and not in the extension function, but would be nice if you add this functionality for kotlin or create extension functions for eventbus