import java.util.Arrays; /** * * @author Daniel Heinrich */ public class Test { void test1() { try{ E[] a = alloc(3); System.out.println("test1 win"); }catch(Throwable t) { System.out.println("test1 fail"); } } void test2() { try{ E b = null; E[] a = alloc(3, b); System.out.println("test2 win"); }catch(Throwable t) { System.out.println("test2 fail"); } } public static T[] alloc(int length, T... base) { return Arrays.copyOf(base, length); } public static void main(String[] args) { Test a = new Test<>(); a.test1(); a.test2(); } }