You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi bennidi, first of all, thanks for all your hard work on the project.
I'm using MBassador 1.2 and I have a question regarding passing generic messages.
Hi Paul,
you assume correctly that the behaviour you describe is expected. The reason is, as you pointed out, the result of Java Type Erasure. However, it has nothing to do with the use of reflection because generic types of method signatures are preserved and available to the reflection API. What you can not do is get the actual generic type of an object at runtime when it is not part of its signature. Example:
class CustomEvent<T>{}
class SimpleEvent extends CustomEvent<Integer> {
// the generic type of instances of this class WILL be available at runtime
}
public void handle(CustomEvent event){}
// when you call
handle(new SimpleEvent()); // then inspecting the generic parameter will give you "Integer" because the generic type is part of the class signature
// but when you call
handle(new CustomEvent<Integer>()); // then the inspection will yield "T" --> the actual type has been erased
Check out this post to see how to get generic type parameters of methods.
But MBassador DOES NOT YET SUPPORT the inspection of generic types at all, so you have to use subclasses or the Java EL filtering mechanism.
Hi bennidi, first of all, thanks for all your hard work on the project.
I'm using MBassador 1.2 and I have a question regarding passing generic messages.
Suppose I have a class that supports generics
When I publish a GenericEvent, I notice that all handlers for GenericEvent gets called. For example, the following code:
produces the following output:
Is this expected?
I hope that only handlers with classes that are compatible with the message are called.
Thank you.
The text was updated successfully, but these errors were encountered: