Java 如何通过Sun的codemodel使用method.param()生成泛型参数类型?
我希望在生成的构造函数中生成一个包含泛型参数类型的签名。输出将如下所示:Java 如何通过Sun的codemodel使用method.param()生成泛型参数类型?,java,generics,code-generation,sun,Java,Generics,Code Generation,Sun,我希望在生成的构造函数中生成一个包含泛型参数类型的签名。输出将如下所示: public Constructor(FooA fooA, FooB<FooC> fooB) { super(fooA, fooB); } constructor.getGenericParameterTypes将返回类型[],但为了通过method.param填充方法的参数,我需要传入一个JVar类型 我认为代码生成器将如下所示: for (int i = 0; i < pt.length;
public Constructor(FooA fooA, FooB<FooC> fooB) {
super(fooA, fooB);
}
constructor.getGenericParameterTypes将返回类型[],但为了通过method.param填充方法的参数,我需要传入一个JVar类型
我认为代码生成器将如下所示:
for (int i = 0; i < pt.length; i++) {
if (gt[i] instanceof Class) {
constructorMethod.param(pt[i], s);
} else if (gt[i] instanceof ParameterizedType) {
constructorMethod.param(gt[i], s);
}
其中pt是对getParameterTypes的调用,gt是对getGenericParameterTypes的调用。除了constructorMethod.paramgt[i],s;是非法语句,因为method.param将不接受参数化类型,并且我无法将参数化类型强制转换为类
使用泛型类型生成签名的更好方法是什么