I've become very fond of Google Gauva's EventBus, so much that I want to include it in one of my Swing GridBagBuilder API's. The goal is to take a Swing component and do something with it in an arbitrary event, and subscribe this to an EventBus. The problem is I think the reflection operations done by the EventBus are not liking my generics for any arbitrary event type.
Essentially, the method accepts a BiConsumer where C is a Swing Component and E is an arbitrary event type to subscribe to EventBus.
public <E> void subscribe(EventBus eventBus, BiConsumer<C,E> consumer) {
eventBus.register(new Object() {
@Subscribe
public void processEvent(E event) {
try {
consumer.accept(comp, event);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
The event bus seems to be working but I keep getting bizarre ClassCastException
errors. Is there any way I can make this work? Or is what I'm trying to achieve a lost cause?
Aucun commentaire:
Enregistrer un commentaire