Monday, November 30, 2009

Java Generics and Recursive Assembly

I was working on a programming assignement, in which I used the following helper class:

private static ArrayList fromArrayToCollection(E[] a) {
ArrayList al = new ArrayList();
for (E o : a) {
if(o != null)
al.add(o);
}
return al;
}

but I wanted to write something that would recursively return an ArrayList for multi-dimensional arrays. Which I would have compile, but would receive various runtime issues with the values not being loaded into the return value.