No, you can't register a static
method with an EventBus
... not directly. First of all, I'd strongly recommend trying to avoid a need for this to begin with. Static state like you have in SampleMailer
is a smell.
That said, there's a pretty simple workaround here using an anonymous inner class:
eventBus.register(new Object() {
@Subscribe
public void loadConfig(ConfigurationChangeEvent cce) {
SampleMailer.loadConfig(cce);
}
});
But again, it should really probably be an instance method on something to begin with.
Edit: Huh, looks like EventBus
will register a static method given an instance of that class. Still, I wouldn't recommend taking advantage of that: EventBus
is based around registration of object instances as subscribers, and static subscriber methods interact somewhat strangely with that.