我正在尝试使以下逻辑起作用:
public class Wrapper {
public static class General {
public void copy(General g) {
// copy fields
}
// General contents.
}
public static class Specific extends General {
// Specific contents.
}
public static class GeneralLogic<T extends General> {
public T load(ResultSet rs) {
General o = new General();
// Do stuff
return new General();
}
}
public static class SpecificLogic<T extends Specific> extends GeneralLogic<T> {
@Override
public T load(ResultSet rs) {
Specific o = new Specific();
o.copy(super.load(rs));
// Do stuff
return new Specific();
}
}
}
两个返回行都会导致编译错误:(Type mismatch: cannot convert from Wrapper.General to T
对于Wrapper.Specific to T
第二个返回)。