Commit 6aa6d68b authored by michael lundquist's avatar michael lundquist
Browse files

About to delete this code. Clone is protected in Java's Cloneable interface, so it doesn't work.

parent 36ad56bf
......@@ -4,26 +4,34 @@ import java.util.Arrays;
import java.util.Random;
public class Examples{
public static void main(String[] args){
randomExample();
//CustomS_B[] vars = {new Examples.CustomS_B("abc"),new Examples.CustomS_B("DEF"),new Examples.CustomS_B("ghi")};
//vars.clone();
Integer[] vars = {1,2,3,4};
System.out.println(Arrays.toString(deepClone(vars)));
}
public Object[] deepClone(Object[] o){
Class oType = o.getClass();
Object[] newClone = Array.newInstance(oType, o.length);
for(int k=0; k < contacts.length; k++){
try{
Method clone = o[k].getMethod("clone", new Class[0]);
newClone[k] = (Object) clone.invoke(obj, args);
}catch(NoSuchMethodException e){
e.printStackTrace();
/**
* A way of cloning an array of clonables.
* Works with multi dimensional arrays
*/
public static Integer[] deepClone(Integer[] o){
//Class oType = o.getClass();
//Cloneable[] newClone = o.clone();//Array.newInstance(oType, o.length);
Integer[] newClone = o.clone();
for(int k=0; k < o.length; k++){
if(o[k].getClass().isArray()){
newClone[k] = deepClone((Integer[]) o[k]);
}else{
Cloneable newObj = o[k];
newClone[k] = newObj.clone();
}
}
return newClone;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment