【发布时间】:2010-04-26 21:22:29
【问题描述】:
Google Guice 提供了一些很棒的依赖注入功能。
我最近遇到了 @Nullable 功能,它允许您将构造函数参数标记为可选(允许为空),因为 Guice 默认情况下不允许这些:
例如
public Person(String firstName, String lastName, @Nullable Phone phone) {
this.firstName = checkNotNull(firstName, "firstName");
this.lastName = checkNotNull(lastName, "lastName");
this.phone = phone;
}
https://github.com/google/guice/wiki/UseNullable
人们使用 Guice 的其他有用功能(尤其是不太明显的功能)有哪些?
【问题讨论】:
-
这是一个隐藏功能吗?它位于最佳实践指南中,从主页单击两次即可。
-
其实是三个,如果你想学究气的话......!
标签: dependency-injection guice