MyClass
Burada Genel yapısı nedeniyle enjekte edilemiyorum.Hançer 2 Genel Tür sınıfı hata enjekte
Dagger bu hata ile yakınır:
Error:(187, 10) error: com.test.MyClass has type parameters, cannot members inject the raw type. via: com.test.MyComponent.inject(com.test.MyClass obj) [component injection method for type: com.test.MyClass]
Biraz googled ancak bu durum senaryosu için bir çözüm bulamadı.
class MyClass<Type> {
@Inject
UserCredentials userCredentials;
ResultProducer<Type> mRP;
public MyClass(ResultProducer<Type> resultProd) {
mRP = resultProd;
Injector.getComponent().inject(this);
}
public Type getResult() {
if (userCredentials.isLoggedIn()) {
mRP.get();
} else {
mRP.getAnonymousCache();
}
}
}
@Component(modules = CredentialsModule.class)
interface MyComponent {
void inject(MyClass obj);
}
@Module
class CredentialsModule {
@Provides
public UserCredentials provideUserCredentials() {
return new UserCredentials();
}
}
enjekte etmek alanların bir sürü varsa bu yaklaşım sakıncalı olabilir soyut sınıflar, arayüzler ve tip parametrelerine dikkat edin (<>)! – vanomart