我正在开发一款Android应用程序,尝试向一个抽象类BaseListFragment中的参数化类型字段进行注入:
public abstract class BaseListFragment<E, A extends ArrayAdapter<E>, S> extends BaseFragment
{
@Inject protected S service;
}
但是我在编译时遇到了以下错误: 错误:找不到符号类S
以下是我的BaseFragment代码:
public class BaseFragment extends Fragment
{
@Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
((App) getActivity().getApplication()).inject(this);
}
}
这是我的服务模块:
@Module(
complete = false,
library = true
)
public class ServiceModule
{
@Provides @Singleton BucketService provideBucketService(RestAdapter restAdapter)
{
return restAdapter.create(BucketService.class);
}
@Provides @Singleton ProjectService provideProjectService(RestAdapter restAdapter)
{
return restAdapter.create(ProjectService.class);
}
@Provides @Singleton ShotService provideShotService(RestAdapter restAdapter)
{
return restAdapter.create(ShotService.class);
}
@Provides @Singleton TeamService provideTeamService(RestAdapter restAdapter)
{
return restAdapter.create(TeamService.class);
}
@Provides @Singleton UserService provideUserService(RestAdapter restAdapter)
{
return restAdapter.create(UserService.class);
}
}
以下是一个继承BaseListFragment类的示例:
public class ProjectFragment extends BaseEntityFragment<Project, ProjectViewAdapter, ProjectService>
{
}
有没有办法注入参数化类型?
敬礼,