Java has List.toArray() to convert a list to Object[]. I want to convert a list of A to an array of A rather than Object. This is my code:
public static <A> A[] toArray(List<A> list) {
A[] rtn = null;
if (list != null) {
int mi = list.size();
rtn = new A[mi];//Error: Cannot create a generic array of A
for (int i = 0; i < mi; i++) {
rtn[i] = list.get(i);
}
}
return rtn;
}
However the line with note causes an error: Cannot create a generic array of A.
How can I bypass this?