public static Object mimicArray(Object array,Class<?> newType){
  int dims=0;
  Class<?> arrayClass=array.getClass();
  while (arrayClass != null && arrayClass.isArray()) {
    arrayClass=arrayClass.getComponentType();
    dims+=1;
  }
  Object mimic;
  if (dims > 1) {
    Object[] xarray=(Object[])array;
    int[] dimens=new int[dims];
    dimens[0]=xarray.length;
    mimic=ArrayFuncs.newInstance(newType,dimens);
    for (int i=0; i < xarray.length; i+=1) {
      Object temp=mimicArray(xarray[i],newType);
      ((Object[])mimic)[i]=temp;
    }
  }
 else {
    mimic=ArrayFuncs.newInstance(newType,Array.getLength(array));
  }
  return mimic;
}

public static Object mimicArray ( Object array , Class < ? > newType ) { int dims = 0 ; Class < ? > arrayClass = array . getClass ( ) ; while ( arrayClass != null && arrayClass . isArray ( ) ) { arrayClass = arrayClass . getComponentType ( ) ; dims += 1 ; } Object mimic ; if ( dims > 1 ) { Object [ ] xarray = ( Object [ ] ) array ; int [ ] dimens = new int [ dims ] ; dimens [ 0 ] = xarray . length ; mimic = ArrayFuncs . newInstance ( newType , dimens ) ; for ( int i = 0 ; i < xarray . length ; i += 1 ) { Object temp = mimicArray ( xarray [ i ] , newType ) ; ( ( Object [ ] ) mimic ) [ i ] = temp ; } } else { mimic = ArrayFuncs . newInstance ( newType , Array . getLength ( array ) ) ; } return mimic ; }
create an array of a type given by new type with the dimensionality given in array .
