Guava EventBus 中的注解与接口 [英] Annotations vs. Interface in Guava EventBus

查看:29
本文介绍了Guava EventBus 中的注解与接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Guava 开发人员选择使用注释:

The Guava developers chose to use annotations:

class EventBusChangeRecorder {
  @Subscribe 
  void recordCustomerChange(ChangeEvent e) {
    recordChange(e.getChange());
  }
}

... 而不是经典界面:

... instead of classic interfaces:

class EventBusChangeRecorder implements Handler<ChangeEvent>{
  void handle(ChangeEvent e) {
    recordChange(e.getChange());
  }
}

这使得编译时检查变得不可能.所以我想知道这种方法的优势是什么.

This makes compile time checking impossible. So I'm wondering what is the advantage of this approach.

您在这里看到注释有什么优势吗?

Do you see any advantages of annotations here?

推荐答案

我认为这个问题在 Guava wiki.

I think that the question is answered on the Guava wiki.

这篇关于Guava EventBus 中的注解与接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆