注释与接口番石榴EventBus [英] Annotations vs. Interface in Guava EventBus

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

问题描述

借助番石榴开发人员选择使用注释:

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?

推荐答案

我认为问题是在番石榴<回答了href=\"http://$c$c.google.com/p/guava-libraries/wiki/EventBusExplained#Why_use_an_annotation_to_mark_handler_methods,_rather_than_requi\">wiki.

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

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

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