为什么我的Java泛型代码在语法上不正确?

Pet*_*háč 0 java generics

你能解释为什么这段代码在语法上不正确吗?

private void addEditor(final Class<? extends FieldEditor> fieldEditorClass, final Composite parent, final PropertyKey propertyKey, final String displayName){
    final Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
    final FieldEditor fieldEditor = new >>fieldEditorClass<< (propertyKey.toString(), displayName, composite);
    initializeFieldEditor(fieldEditor);     
}
Run Code Online (Sandbox Code Playgroud)

第5行,之间的部分>>,并<<有红色下划线,它说"不能解析为一个类型".

我希望你能看到我在这里想要实现的目标.通过将SomeEditor.class传递给此方法,我想创建此类的对象并初始化它.我该如何解决第5行的问题?


基本上,我想参数化由此代码实例化的具体FieldEditor类.我的代码中有几个基本相同的方法,除了每个方法实例化一个不同类的FieldEditor.

yaw*_*awn 5

您需要使用例如Reflection实例化类.在SO上看到这个答案.