panda.lang.reflect.ArrayCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.lang.reflect;
import java.lang.reflect.Array;
import panda.lang.Creator;
import panda.lang.Exceptions;
public class ArrayCreator implements Creator {
private Class clazz;
private int length;
/**
* @param clazz array clazz
* @param length
*/
public ArrayCreator(Class clazz, int length) {
this.clazz = clazz;
this.length = length;
}
@Override
@SuppressWarnings("unchecked")
public T create(Object... args) {
try {
return (T)Array.newInstance(clazz.getComponentType(), length);
}
catch (Exception e) {
throw Exceptions.wrapThrow(e);
}
}
}