Documentation / listeners / com.femastudios.listeners / ReflectionListenersManager

ReflectionListenersManager

open class ReflectionListenersManager<Interface : Any> : BaseListenersManager<Interface>, CallableListenersManager<Interface>

This implementation of ListenersManager is the easiest to use. Through reflection, it is possible to use it without the need to write any custom code.

If the given Interface overrides the invoke operator, the usage becomes even simpler:

interface OnSomethingHappens {
	operator fun invoke(item: Int)
	fun anotherCallback(item: Int)
}

...

val manager = ReflectionListenersManager(OnSomethingHappens::class.java)
manager.addStrongly(...)
manager.call(21) //Calls OnSomethingHappens.invoke() on each registered listener
manager.call.anotherCallback() //Calls OnSomethingHappens.anotherCallback() on each registered listener

Since this class uses reflections, it's not suitable for code that must be highly efficient. In that case, it is suggested to extend BaseListenersManager, and make the appropriate calls to callListeners.

Constructors

<init>

This implementation of ListenersManager is the easiest to use. Through reflection, it is possible to use it without the need to write any custom code.

ReflectionListenersManager(cls: Class<out Interface>)

Properties

call

Returns a class that implements Interface, from which you can call the listener methods

open val call: Interface

Functions

handleProxyInvocation

Calls method with the given args on the listeners.

open fun handleProxyInvocation(method: Method, args: Array<Any>?): Unit