ziggy42
03/19/2018, 12:11 PMtypealias Listener<T> = (T) -> Unit
and for each T
that I accept I need to store the list of registered listeners: val userListeners = mutableListOf<Listener<User>>()
. But this forces me to have N lists for N possible T
. Is there a better way?spand
03/19/2018, 12:22 PMdata class UserTypeKey(val user: User, val type: Type)
val listenerMap = mutableMapOf<UserTypeKey, Listener>()
ziggy42
03/19/2018, 12:26 PMmutableMapOf<T, Listener<T>>()
?Andreas Sinz
03/19/2018, 12:42 PMMap<KClass<*>, MutableList<Function<Unit>>>
and then based on the T::class
you can retrieve the list of Listeners, but that involves unsafe casts