这里有一种不显式使用构造函数参数的相当人为的方法。您需要扩展参数化抽象类。public class Test {
public static void main(String [] args) throws Exception {
Generic g = new Generic();
g.initParameter();
}}import java.lang.reflect.ParameterizedType;public abstract class GenericAbstract {
protected T parameter;
@SuppressWarnings("unchecked")
void initParameter() throws Exception, ClassNotFoundException,
InstantiationException {
// Get the class name of this instance's type.
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];
// Instantiate the Parameter and initialize it.
parameter = (T) Class.forName(parameterClassName).newInstance();
}}public class Generic extends GenericAbstract {}public class Foo {
public Foo() {
System.out.println("Foo constructor...");
}}