我的代码是:
class ReferenceRangeBuilder<T extends DvOrderedBuilder> {
private DvTextBuilder meaningBuilder;
private DvIntervalBuilder<T> rangeBuilder;
public ReferenceRangeBuilder() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
}
}
我想启动 rangeBuilder,以便我可以在其中设置值。我想在构造函数中做到这一点。对于 DvIntervalBuilder rangeBuilder 我这样做了:
public DvIntervalBuilder() throws NoSuchFieldException, InstantiationException, IllegalAccessException, ClassNotFoundException {
ParameterizedType pt = (ParameterizedType) getClass().getGenericSuperclass();
// You may need this split or not, use logging to check
String parameterClassName = pt.getActualTypeArguments()[0].toString().split("\\s")[1];
T lower = (T) Class.forName(parameterClassName).newInstance();
T upper = (T) Class.forName(parameterClassName).newInstance();
}