@Test public void testNewArrayCompat() { String[] strings = new String[] {"abc", "def", "fff"}; String[] copy = Compat.newArrayCompat(strings, 5); assertEquals(5, copy.length); assertEquals("abc", copy[0]); assertNull(copy[3]); String[] empty = new String[0]; String[] emptyCopy = Compat.newArrayCompat(empty, 3); assertEquals(3, emptyCopy.length); emptyCopy = Compat.newArrayCompat(empty, 0); assertEquals(0, emptyCopy.length); }
@SuppressWarnings("unchecked") public static <E> E[] newArrayCompat(E[] array, int length) { final E[] res = (E[]) Array.newInstance(array.getClass().getComponentType(), length); System.arraycopy(array, 0, res, 0, Math.min(length, array.length)); return res; }
Compat { @SuppressWarnings("unchecked") public static <E> E[] newArrayCompat(E[] array, int length) { final E[] res = (E[]) Array.newInstance(array.getClass().getComponentType(), length); System.arraycopy(array, 0, res, 0, Math.min(length, array.length)); return res; } }
Compat { @SuppressWarnings("unchecked") public static <E> E[] newArrayCompat(E[] array, int length) { final E[] res = (E[]) Array.newInstance(array.getClass().getComponentType(), length); System.arraycopy(array, 0, res, 0, Math.min(length, array.length)); return res; }  }
Compat { @SuppressWarnings("unchecked") public static <E> E[] newArrayCompat(E[] array, int length) { final E[] res = (E[]) Array.newInstance(array.getClass().getComponentType(), length); System.arraycopy(array, 0, res, 0, Math.min(length, array.length)); return res; }  @NotNull static Queue<T> queue(); static E[] newArray(int length, E... array); @SuppressWarnings("unchecked") static E[] newArrayCompat(E[] array, int length); }
Compat { @SuppressWarnings("unchecked") public static <E> E[] newArrayCompat(E[] array, int length) { final E[] res = (E[]) Array.newInstance(array.getClass().getComponentType(), length); System.arraycopy(array, 0, res, 0, Math.min(length, array.length)); return res; }  @NotNull static Queue<T> queue(); static E[] newArray(int length, E... array); @SuppressWarnings("unchecked") static E[] newArrayCompat(E[] array, int length);  }