我有一个带有通用类型参数的抽象类,但是内部类似乎无法访问此类型:
public abstract class DataProcessor<T> {
protected interface CallBack {
List<T> parse(String response) throws ServerException, JSONException;// error
}
}
有什么问题?
更新:
用法:
public class XProcessor extend DataProcessor<X>{
}
public class YProcessor extend DataProcessor<Y>{
}
XProcessor xp=new XProcessor();
YProcessor yp=new YProcessor();
xp.setCallback(new DataProcessor.CallBack<X>(){
....
});
但是我认为,由于XProcessor
已经在定义的X
类中定义了,因此我想知道是否可以忽略这样的通用参数:
xp.setCallback(new XProcessor.CallBack(){ //without specify the generic type
.....
});
您的打算是不可能的。为避免编译错误,将type参数添加到Callback
接口。
public abstract class DataProcessor<T> {
protected interface CallBack<T> {
List<T> parse(String response) throws ServerException, JSONException;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句