I have abstract class with a generic type parameter, but it seems that the inner class can not access this type:
public abstract class DataProcessor<T> {
protected interface CallBack {
List<T> parse(String response) throws ServerException, JSONException;// error
}
}
What's the problem?
update:
Usage:
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>(){
....
});
But I thought that since the XProcessor
have defined the X
in the class defined, so I wonder if I can ignore the generic parameter like this:
xp.setCallback(new XProcessor.CallBack(){ //without specify the generic type
.....
});
It is not possible for you are intending. To avoid compilation error add the type parameter to Callback
interface.
public abstract class DataProcessor<T> {
protected interface CallBack<T> {
List<T> parse(String response) throws ServerException, JSONException;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.