Andreas Leitgeb wrote:
> The other question was, if there exists some method for deepCopying
> an array of Cloneables.
I don't know of any standard method to do that. However, it's not so
hard to roll your own.
Here is one possible approach presented:
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.IdentityHashMap;
import java.util.Map;
public class ArraysCloning {
public static void main(String[] args) {
String[][] a0 = {{"a"}, {"b", "c"}};
String[][] a1 = a0.clone();
String[][] a2 = Arrays.copyOf(a0, a0.length);
String[][] a3 = deepClone(a0);
a0[1][1] = "c'";
System.out.println("a0=" + Arrays.deepToString(a0));
System.out.println("a1=" + Arrays.deepToString(a1));
System.out.println("a2=" + Arrays.deepToString(a2));
System.out.println("a3=" + Arrays.deepToString(a3));
}
public static T[] deepClone(T[] a) {
return deepClone(a, new IdentityHashMap