Bay Max
Bay Max

Reputation: 232

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

What is the difference between the two while providing binding using Google Guice?

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

Upvotes: 1

Views: 879

Answers (1)

Jan Galinski
Jan Galinski

Reputation: 12003

If used the way you do in your example, there is no difference. The first line binds to exactly the class AImpl, the second line binds to a class that matches (isassignable from) A.class. Using the Key wrapper will allow you to bind on generic types and annotated types if you are using more complex use cases.

Upvotes: 2

Related Questions