Binder.bind 在 Google Guice 中使用 Key 和不使用 Key 的区别?

Difference between Binder.bind using Key and without Key in Google Guice?

两者在使用 Google Guice 提供绑定时有什么区别?

bind(A.class).to(AImpl.class)
bind(A.class).to(Key.get(AImpl.class))

如果按照您示例中的方式使用,则没有区别。第一行绑定到 class AImpl,第二行绑定到匹配(可分配自)A.class 的 class。 如果您使用更复杂的用例,使用密钥包装器将允许您绑定泛型类型和带注释的类型。