/** * * @author Dmitry Leskov */ import java.lang.reflect.Array; public class GenericArrayFactory { public Item[] arrayOf(Class clazz, int length) { return clazz.cast(Array.newInstance(clazz.getComponentType(), length)); } public static void main(String[] args) { Integer[] intArray = new GenericArrayFactory().arrayOf(Integer[].class, 42); } }