Untargetted Bindings
You may create bindings without specifying a target. This is most useful for concrete classes and types annotated by either @ImplementedBy or @ProvidedBy. An untargetted binding informs the injector about a type, so it may prepare dependencies eagerly. Untargetted bindings have no to clause, like so:
bind(MyConcreteClass.class);
bind(AnotherConcreteClass.class).in(Singleton.class);When specifying binding annotations, you must still add the target binding, even it is the same concrete class. For example:
bind(MyConcreteClass.class).annotatedWith(Names.named("foo")).to(MyConcreteClass.class);
bind(AnotherConcreteClass.class).annotatedWith(Names.named("foo")).to(AnotherConcreteClass.class).in(Singleton.class);
is bind(MyConcreteClass?.class); the same as
@Provides MyConcreteClass? provideMyConcreteClass(){ ... }?
No.
An untargetted binding simply tells the injector that whenever an instance of MyConcreteClass? is requested it should create one and inject it. Whereas the provides method tells the injector that this method should be invoked whenever an instance of MyConcreteClass? is requested and use the returned value to inject.
The key difference is that the instance will be created by Guice in one case and by your code in the other. There are a few things that will only work for instance created by Guice - AOP method interception being the main one.
In general I'd recommend that you only use provider methods when you've got non-trivial logic required to create the instance. Usually this means that you'll have a non-zero number of parameters to the provider method that you'd use to create the instance.