我有一种方法可以为所需类型构建数组。它适用于原始类型。但是当我有一组自定义对象时,它就不起作用了。所以我已经对其进行了调整。但它仍然失败。代码是这样的:
private Object buildArray( String type, Object object) {
final Class<?> requiredType = loadClass(type);
final String typeName = type.substring(2).replace(";", "").trim();
Object[] array = ((Object[]) object);
ArrayList<Object> arrayList = new ArrayList<Object>(array.length);
for (Object customObj : array) {
arrayList.add(castToRequiredType(typeName, customObj));
}
return arrayList.toArray();
}
在 this castToRequiredType
: 中,将其转换CustomObject
为CustomType
类CustomType
。并且要构建的数组是类型CustomType
。我被困在动态构建CustomType
.
欢迎在这个方向提供任何帮助。提前致谢。