我有一个使用反射来填充数组的Object[]
方法,该方法当前返回 Object[],我想将它转换为创建的实际反射类实例。例如:
public Object[] populateReflectionObject(Class<?> c) {
Object[] reflectionArrayPopulated = methodToCreateArrayFromReflection(c);
return reflectionArrayPopulated;
}
FinalObject[] populate = (Object[])populateReflectionObject(FinalObject.class);
无法在数组之间进行转换,是否可以通过使用泛型来实现我想要的?
编辑:我创建了我想要投射的对象:
Object[] object = new Object[finalObjectArray.length];
for (int i = 0; i < finalObjectArray.length; i++) {
object[i] = finalObjectArray;
}