There is a generic fragment
public class MyFragment<TYPE> extends Fragment {
@Inject
SomeClass class;
public MyFragment(){}
}
}
I am not able to add this Fragment to the Fragment Binding Module as Dagger complains it is of raw type.
How do I mention the TYPE class in the binding module?
My binding module looks like this for now:
@Module
public abstract class BindingModule {
@ContributesAndroidInjector(modules = MyFragmentModule.class)
abstract MyFragment bindMyFragment();
}
Error
error: [dagger.android.AndroidInjector.inject(T)] MyFragment has type parameters, cannot members inject the raw type.
First I have to say that the fragment is special class it's instantiation must be done by OS, By adding it to your module you round the life cycle of fragment which must be control by OS.
https://google.github.io/dagger/android
However if you wish to provide it by module you have to use Qualifiers for generic types. Change your module as following:
So wherever you what to inject it, you have to specify the type and it's Qualifier: