Im trying to figure out what a annotation does that is created in code i have inherited.
Here is the annotation definition per code:
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.inject.Qualifier;
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
public @interface BaseUrl {
}
then using dagger 2 ( a dependency injection framework for android), its used like this:
//from a file called applicationModule.java
@Provides
@Singleton
Endpoint provideBaseURL(@BaseUrl String url) {
return getEndPointUrl(url);
}
I am more concerned about the @BaseUrl annotation. what does it do in this context ?
The project uses Retrofit.
I finally found what whats happening and i'd like to share. Dagger has two ways to help when type alone cannot identify a provider. Either use @named or @Qualifier annotation. The @named annotation can be used as default but if you want to create your own annotation for identifying a provider you can use @Qualifier.
So in the example i provided the @BaseURL is nothing more then a @Named tag to attach to a provider. They do the same thing but instead of using the word "Named" which is provided by dagger, you can make your own. The docs are here under qualifier section.