Cannot create a generic array of T
程序员文章站
2022-06-11 08:28:43
...
public static <T> T[] createArray(List<T> list,Class<T> clazz){ T[] array = (T[]) Array.newInstance(clazz, list.size()); for(int i = 0; i < array.length; i++){ array[i] = list.get(i); } return array; }