我正在尝试以编程方式初始化一个类并将其添加到列表中。我不知道如何输入workflowClass
以便extends BaseWorkflow
列表接受它。目前它说我不能Object
在期待的时候添加? extends BaseWorkflow
。
private static List<? extends BaseWorkflow> workflowList = new ArrayList<BaseWorkflow>();
/**
* Initialize the production line
*/
public static void init() {
//load active workflows into memory
WorkflowService workflowService = (WorkflowService) ApplicationContextProvider.getApplicationContext().getBean("workflowService");
for (Workflow workflow: workflowService.findActive()) {
try {
Class<?> clazz = Class.forName(workflow.getClassName());
Object workflowClass = clazz.newInstance();
workflowList.add(workflowClass);