扩展类和实现接口的泛型类
为了减少类的依赖性,我想将参数(使用泛型类)发送到扩展某些类并实现接口的构造函数,例如
public interface SomeInterface{
public void someMethod();
}
public class MyFragment extends Fragment implements SomeInterface{
//implementation
}
//here is classs, that I need to create. T must extend Fragment and implements
//SomeInterface. But, I'm afraid, if I'll use MyFragment directly, it will create a
//dependence of SomeClass from MyFragment.
public class SomeClass /*generic?*/ {
public SomeClass(T parent);
}
可能吗?
此外,使用我的 T 类,我想创建视图,使用 T.getActivity() 作为上下文。