1
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
public class Test {
public static class Processing { }
public static class ProcessingResults { }
public static class ProcessingFinished { }
public static EventBus bus = new EventBus();
@Subscribe
public void receiveStartRequest(Processing evt) {
System.out.println("Got processing request - starting processing");
}
@Subscribe
public void processingStarted(Processing evt) {
System.out.println("Processing has started");
}
@Subscribe
public void resultsReceived(ProcessingResults evt) {
System.out.println("got results");
}
@Subscribe
public void processingComplete(ProcessingFinished evt) {
System.out.println("Processing has completed");
}
public static void main(String[] args) {
Test t = new Test();
bus.register(t);
bus.post(new Processing());
}
}
因此,在上面的例子中,可以看出有2个用户接受相同类型的处理。现在,在post()中,所有函数都会被调用?如果2个函数receiveStartRequest和processingStarted会被调用,那么它们将按哪个顺序被调用?番石榴EventBus多用户相同tpe
但我的问题是如果我们不这样做会发生什么?这两个用户会被叫到吗? – hatellla
@hatellla其实我开始写这篇文章作为评论,但在中途我认为答案会更好,我忘了包括那部分。我现在回答了这个问题。对不起,不要更小心:) –
非常感谢@Oliver – hatellla