Below is the syntax highlighted version of GenericArrayFactory.java
from §1.3 Stacks and Queues.
/** * * @author Dmitry Leskov */ import java.lang.reflect.Array; public class GenericArrayFactory<Item> { public Item[] arrayOf(Class<Item[]> clazz, int length) { return clazz.cast(Array.newInstance(clazz.getComponentType(), length)); } public static void main(String[] args) { Integer[] intArray = new GenericArrayFactory<Integer>().arrayOf(Integer[].class, 42); } }