Ast*_*isk 9 java generics android parse-platform
我需要一种方法来根据用户的选择查询不同的解析类.我解决了这个问题如下.请告知如何解决我的问题或建议替代/更好的方法.
我有A, B, C, ...
与Parse类相对应的类.它们非常相似.所以,我创建了抽象类Q
:
public abstract class Q extends ParseObject {
// some shared methods
public abstract ParseQuery<? extends Q> getQuery();
}
Run Code Online (Sandbox Code Playgroud)
每个A, B, C, ...
定义为:
@ParseClassName("A")
public class A extends Q {
private static final A INSTANCE = new A();
@Override
public ParseQuery<A> getQuery() {
return ParseQuery.getQuery(A.class);
}
public static A getInstance(){
return INSTANCE;
}
}
Run Code Online (Sandbox Code Playgroud)
比我的回收视图有以下回收适配器:
public class QAdapter extends ParseRecyclerQueryAdapter<Q,QAdapter.MyViewHolder>{ ... }
Run Code Online (Sandbox Code Playgroud)
我得到的错误发生在我的激活中的以下行:
mRecyclerAdapter = new QAdapter(this, factory, true);
Run Code Online (Sandbox Code Playgroud)
错误消息是:
Error:(58, 70) error: incompatible types: QueryFactory<CAP#1> cannot be converted to QueryFactory<Q>
where CAP#1 is a fresh type-variable:
CAP#1 extends Q from capture of ? extends Q
Run Code Online (Sandbox Code Playgroud)
我尝试将适配器类的定义设为泛型public class QAdapter<T extends Q> extends ParseRecyclerQueryAdapter<T, QAdapter.MyViewHolder> {... }
,但这引入了另一个错误,即QAdapter onBindViewHolder
即使实现也没有实现.
小智 0
这可能不起作用,但我会尝试更换
public class QAdapter extends ParseRecyclerQueryAdapter<Q,QAdapter.MyViewHolder>{ ... }
Run Code Online (Sandbox Code Playgroud)
和
public class QAdapter extends ParseRecyclerQueryAdapter<? extends Q,QAdapter.MyViewHolder>{ ... }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
328 次 |
最近记录: |