guava EventBus 消息总线的运用

public class Test {

    public static void main(String[] args) {
        final EventBus eventBus = new EventBus();
        eventBus.register(new Object() {

            @Subscribe
            public void lister(Integer integer) {
                System.out.printf("%s from int%n", integer);
            }

            @Subscribe
            public void lister(Number integer) {
                System.out.printf("%s from Number%n", integer);
            }

            @Subscribe
            public void lister(Long integer) {
                System.out.printf("%s from long%n", integer);
            }
        });

       // eventBus.post(1);
       // eventBus.post(1L);


        final EventBus eventBus1 = new EventBus();
        eventBus1.register(new Object() {

            @Subscribe
            public void lister(DeadEvent event) {
                System.out.printf("人才+ %s=%s from dead events%n", event.getSource().getClass(), event.getEvent());
            }
        });

        eventBus1.post(new Object());
    }
}

 

 

https://www.cnblogs.com/whitewolf/p/4132840.html

 

posted @ 2018-07-12 17:25  全力以赴001  阅读(531)  评论(0编辑  收藏  举报