Reputation: 36028
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
.....
});
Upvotes: 1
Views: 92
Reputation: 15244
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;
}
}
Upvotes: 2