Finalize 方法
2023年10月22日小于 1 分钟
泛型写法
public interface InferRowCountFactory {
<T> InferRowCount<T> forType(Class<T> type);
}@Component
public class InferRowCountFactoryImpl implements InferRowCountFactory {
private final Map<Class<?>, InferRowCount<?>> implementationMap;
public InferRowCountFactoryImpl(
InferRowCount4ETLOperator inferRowCount4ETLOperator,
InferRowCount4OperatorBean inferRowCount4OperatorBean) {
this.implementationMap = Map.of(
ETLOperator.class, inferRowCount4ETLOperator,
OperatorBean.class, inferRowCount4OperatorBean
);
}
@SuppressWarnings("unchecked")
@Override
public <T> InferRowCount<T> forType(Class<T> type) {
InferRowCount<?> implementation = implementationMap.get(type);
if (implementation == null) {
throw new UnsupportedOperationException("Unsupported infer row count for type: " + type.getName());
}
return (InferRowCount<T>) implementation;
}
}