Here you can find the source of castNonNullArray( T [] arr)
private static <T extends Object> T [] castNonNullArray( T [] arr)
//package com.java2s; //License from project: GNU General Public License public class Main { private static <T extends /*@Nullable*/ Object> /*@NonNull*/ T /*@NonNull*/ [] castNonNullArray( T /*@Nullable*/ [] arr) { assert arr != null : "Misuse of castNonNullArray: called with a null array argument"; for (int i = 0; i < arr.length; ++i) { assert arr[i] != null : "Misuse of castNonNull: called with a null array element"; checkIfArray(arr[i]);/*from w w w.j av a 2 s. c o m*/ } return (/*@NonNull*/ T[]) arr; } private static void checkIfArray(/*@NonNull*/ Object ref) { assert ref != null : "Misuse of checkIfArray: called with a null argument"; Class<?> comp = ref.getClass().getComponentType(); if (comp != null) { // comp is non-null for arrays, otherwise null. if (comp.isPrimitive()) { // Nothing to do for arrays of primitive type: primitives are // never null. } else { castNonNullArray((Object[]) ref); } } } }