emul/src/main/java/java/lang/reflect/Array.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 18 Jan 2013 21:51:06 +0100
branchArrayReflect
changeset 485 d962d1330e54
parent 484 7ca6bd52b668
child 486 947269b26dc0
permissions -rw-r--r--
Just autoboxing on Arrays remains
     1 /*
     2  * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 package java.lang.reflect;
    27 
    28 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    29 import org.apidesign.bck2brwsr.core.JavaScriptPrototype;
    30 
    31 /**
    32  * The {@code Array} class provides static methods to dynamically create and
    33  * access Java arrays.
    34  *
    35  * <p>{@code Array} permits widening conversions to occur during a get or set
    36  * operation, but throws an {@code IllegalArgumentException} if a narrowing
    37  * conversion would occur.
    38  *
    39  * @author Nakul Saraiya
    40  */
    41 @JavaScriptPrototype(prototype = "new Array", container = "Array.prototype")
    42 public final
    43 class Array {
    44 
    45     /**
    46      * Constructor.  Class Array is not instantiable.
    47      */
    48     private Array() {}
    49 
    50     /**
    51      * Creates a new array with the specified component type and
    52      * length.
    53      * Invoking this method is equivalent to creating an array
    54      * as follows:
    55      * <blockquote>
    56      * <pre>
    57      * int[] x = {length};
    58      * Array.newInstance(componentType, x);
    59      * </pre>
    60      * </blockquote>
    61      *
    62      * @param componentType the {@code Class} object representing the
    63      * component type of the new array
    64      * @param length the length of the new array
    65      * @return the new array
    66      * @exception NullPointerException if the specified
    67      * {@code componentType} parameter is null
    68      * @exception IllegalArgumentException if componentType is {@link Void#TYPE}
    69      * @exception NegativeArraySizeException if the specified {@code length}
    70      * is negative
    71      */
    72     public static Object newInstance(Class<?> componentType, int length)
    73     throws NegativeArraySizeException {
    74         if (length < 0) {
    75             throw new NegativeArraySizeException();
    76         }
    77         String sig = findSignature(componentType);
    78         return newArray(componentType.isPrimitive(), sig, length);
    79     }
    80     
    81     private static String findSignature(Class<?> type) {
    82         if (type == Integer.TYPE) {
    83             return "[I";
    84         }
    85         if (type == Long.TYPE) {
    86             return "[J";
    87         }
    88         if (type == Double.TYPE) {
    89             return "[D";
    90         }
    91         if (type == Float.TYPE) {
    92             return "[F";
    93         }
    94         if (type == Byte.TYPE) {
    95             return "[B";
    96         }
    97         if (type == Boolean.TYPE) {
    98             return "[Z";
    99         }
   100         if (type == Short.TYPE) {
   101             return "[S";
   102         }
   103         if (type == Character.TYPE) {
   104             return "[C";
   105         }
   106         if (type.getName().equals("void")) {
   107             throw new IllegalStateException("Can't create array for " + type);
   108         }
   109         return "[L" + type.getName() + ";";
   110     }
   111     /**
   112      * Creates a new array
   113      * with the specified component type and dimensions.
   114      * If {@code componentType}
   115      * represents a non-array class or interface, the new array
   116      * has {@code dimensions.length} dimensions and
   117      * {@code componentType} as its component type. If
   118      * {@code componentType} represents an array class, the
   119      * number of dimensions of the new array is equal to the sum
   120      * of {@code dimensions.length} and the number of
   121      * dimensions of {@code componentType}. In this case, the
   122      * component type of the new array is the component type of
   123      * {@code componentType}.
   124      *
   125      * <p>The number of dimensions of the new array must not
   126      * exceed the number of array dimensions supported by the
   127      * implementation (typically 255).
   128      *
   129      * @param componentType the {@code Class} object representing the component
   130      * type of the new array
   131      * @param dimensions an array of {@code int} representing the dimensions of
   132      * the new array
   133      * @return the new array
   134      * @exception NullPointerException if the specified
   135      * {@code componentType} argument is null
   136      * @exception IllegalArgumentException if the specified {@code dimensions}
   137      * argument is a zero-dimensional array, or if the number of
   138      * requested dimensions exceeds the limit on the number of array dimensions
   139      * supported by the implementation (typically 255), or if componentType
   140      * is {@link Void#TYPE}.
   141      * @exception NegativeArraySizeException if any of the components in
   142      * the specified {@code dimensions} argument is negative.
   143      */
   144     public static Object newInstance(Class<?> componentType, int... dimensions)
   145         throws IllegalArgumentException, NegativeArraySizeException {
   146         StringBuilder sig = new StringBuilder();
   147         for (int i = 1; i < dimensions.length; i++) {
   148             sig.append('[');
   149         }
   150         sig.append(findSignature(componentType));
   151         return multiNewArray(sig.toString(), dimensions, 0);
   152     }
   153 
   154     /**
   155      * Returns the length of the specified array object, as an {@code int}.
   156      *
   157      * @param array the array
   158      * @return the length of the array
   159      * @exception IllegalArgumentException if the object argument is not
   160      * an array
   161      */
   162     public static int getLength(Object array)
   163     throws IllegalArgumentException {
   164         if (!array.getClass().isArray()) {
   165             throw new IllegalArgumentException("Argument is not an array");
   166         }
   167         return length(array);
   168     }
   169     
   170     @JavaScriptBody(args = { "arr" }, body = "return arr.length;")
   171     private static native int length(Object arr);
   172 
   173     /**
   174      * Returns the value of the indexed component in the specified
   175      * array object.  The value is automatically wrapped in an object
   176      * if it has a primitive type.
   177      *
   178      * @param array the array
   179      * @param index the index
   180      * @return the (possibly wrapped) value of the indexed component in
   181      * the specified array
   182      * @exception NullPointerException If the specified object is null
   183      * @exception IllegalArgumentException If the specified object is not
   184      * an array
   185      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   186      * argument is negative, or if it is greater than or equal to the
   187      * length of the specified array
   188      */
   189     public static Object get(Object array, int index)
   190     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   191         if (array.getClass().getComponentType().isPrimitive()) {
   192             throw new IllegalArgumentException();
   193         } else {
   194             return ((Object[])array)[index];
   195         }
   196     }
   197 
   198     /**
   199      * Returns the value of the indexed component in the specified
   200      * array object, as a {@code boolean}.
   201      *
   202      * @param array the array
   203      * @param index the index
   204      * @return the value of the indexed component in the specified array
   205      * @exception NullPointerException If the specified object is null
   206      * @exception IllegalArgumentException If the specified object is not
   207      * an array, or if the indexed element cannot be converted to the
   208      * return type by an identity or widening conversion
   209      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   210      * argument is negative, or if it is greater than or equal to the
   211      * length of the specified array
   212      * @see Array#get
   213      */
   214     public static native boolean getBoolean(Object array, int index)
   215         throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
   216 
   217     /**
   218      * Returns the value of the indexed component in the specified
   219      * array object, as a {@code byte}.
   220      *
   221      * @param array the array
   222      * @param index the index
   223      * @return the value of the indexed component in the specified array
   224      * @exception NullPointerException If the specified object is null
   225      * @exception IllegalArgumentException If the specified object is not
   226      * an array, or if the indexed element cannot be converted to the
   227      * return type by an identity or widening conversion
   228      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   229      * argument is negative, or if it is greater than or equal to the
   230      * length of the specified array
   231      * @see Array#get
   232      */
   233     public static byte getByte(Object array, int index)
   234     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   235         if (array.getClass().getComponentType() != Byte.TYPE) {
   236             throw new IllegalArgumentException();
   237         }
   238         byte[] arr = (byte[]) array;
   239         return arr[index];
   240     }
   241 
   242     /**
   243      * Returns the value of the indexed component in the specified
   244      * array object, as a {@code char}.
   245      *
   246      * @param array the array
   247      * @param index the index
   248      * @return the value of the indexed component in the specified array
   249      * @exception NullPointerException If the specified object is null
   250      * @exception IllegalArgumentException If the specified object is not
   251      * an array, or if the indexed element cannot be converted to the
   252      * return type by an identity or widening conversion
   253      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   254      * argument is negative, or if it is greater than or equal to the
   255      * length of the specified array
   256      * @see Array#get
   257      */
   258     public static native char getChar(Object array, int index)
   259         throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
   260 
   261     /**
   262      * Returns the value of the indexed component in the specified
   263      * array object, as a {@code short}.
   264      *
   265      * @param array the array
   266      * @param index the index
   267      * @return the value of the indexed component in the specified array
   268      * @exception NullPointerException If the specified object is null
   269      * @exception IllegalArgumentException If the specified object is not
   270      * an array, or if the indexed element cannot be converted to the
   271      * return type by an identity or widening conversion
   272      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   273      * argument is negative, or if it is greater than or equal to the
   274      * length of the specified array
   275      * @see Array#get
   276      */
   277     public static short getShort(Object array, int index)
   278     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   279         final Class<?> t = array.getClass().getComponentType();
   280         if (t == Short.TYPE) {
   281             short[] arr = (short[]) array;
   282             return arr[index];
   283         }
   284         return getByte(array, index);
   285     }
   286 
   287     /**
   288      * Returns the value of the indexed component in the specified
   289      * array object, as an {@code int}.
   290      *
   291      * @param array the array
   292      * @param index the index
   293      * @return the value of the indexed component in the specified array
   294      * @exception NullPointerException If the specified object is null
   295      * @exception IllegalArgumentException If the specified object is not
   296      * an array, or if the indexed element cannot be converted to the
   297      * return type by an identity or widening conversion
   298      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   299      * argument is negative, or if it is greater than or equal to the
   300      * length of the specified array
   301      * @see Array#get
   302      */
   303     public static int getInt(Object array, int index) 
   304     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   305         final Class<?> t = array.getClass().getComponentType();
   306         if (t == Integer.TYPE) {
   307             int[] arr = (int[]) array;
   308             return arr[index];
   309         }
   310         return getShort(array, index);
   311     }
   312 
   313     /**
   314      * Returns the value of the indexed component in the specified
   315      * array object, as a {@code long}.
   316      *
   317      * @param array the array
   318      * @param index the index
   319      * @return the value of the indexed component in the specified array
   320      * @exception NullPointerException If the specified object is null
   321      * @exception IllegalArgumentException If the specified object is not
   322      * an array, or if the indexed element cannot be converted to the
   323      * return type by an identity or widening conversion
   324      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   325      * argument is negative, or if it is greater than or equal to the
   326      * length of the specified array
   327      * @see Array#get
   328      */
   329     public static long getLong(Object array, int index)
   330     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   331         final Class<?> t = array.getClass().getComponentType();
   332         if (t == Long.TYPE) {
   333             long[] arr = (long[]) array;
   334             return arr[index];
   335         }
   336         return getInt(array, index);
   337     }
   338 
   339     /**
   340      * Returns the value of the indexed component in the specified
   341      * array object, as a {@code float}.
   342      *
   343      * @param array the array
   344      * @param index the index
   345      * @return the value of the indexed component in the specified array
   346      * @exception NullPointerException If the specified object is null
   347      * @exception IllegalArgumentException If the specified object is not
   348      * an array, or if the indexed element cannot be converted to the
   349      * return type by an identity or widening conversion
   350      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   351      * argument is negative, or if it is greater than or equal to the
   352      * length of the specified array
   353      * @see Array#get
   354      */
   355     public static float getFloat(Object array, int index)
   356     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   357         final Class<?> t = array.getClass().getComponentType();
   358         if (t == Float.TYPE) {
   359             float[] arr = (float[]) array;
   360             return arr[index];
   361         }
   362         return getLong(array, index);
   363     }
   364 
   365     /**
   366      * Returns the value of the indexed component in the specified
   367      * array object, as a {@code double}.
   368      *
   369      * @param array the array
   370      * @param index the index
   371      * @return the value of the indexed component in the specified array
   372      * @exception NullPointerException If the specified object is null
   373      * @exception IllegalArgumentException If the specified object is not
   374      * an array, or if the indexed element cannot be converted to the
   375      * return type by an identity or widening conversion
   376      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   377      * argument is negative, or if it is greater than or equal to the
   378      * length of the specified array
   379      * @see Array#get
   380      */
   381     public static double getDouble(Object array, int index)
   382     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   383         final Class<?> t = array.getClass().getComponentType();
   384         if (t == Double.TYPE) {
   385             double[] arr = (double[]) array;
   386             return arr[index];
   387         }
   388         return getFloat(array, index);
   389     }
   390 
   391     /**
   392      * Sets the value of the indexed component of the specified array
   393      * object to the specified new value.  The new value is first
   394      * automatically unwrapped if the array has a primitive component
   395      * type.
   396      * @param array the array
   397      * @param index the index into the array
   398      * @param value the new value of the indexed component
   399      * @exception NullPointerException If the specified object argument
   400      * is null
   401      * @exception IllegalArgumentException If the specified object argument
   402      * is not an array, or if the array component type is primitive and
   403      * an unwrapping conversion fails
   404      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   405      * argument is negative, or if it is greater than or equal to
   406      * the length of the specified array
   407      */
   408     public static void set(Object array, int index, Object value)
   409     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   410         if (array.getClass().getComponentType().isPrimitive()) {
   411             throw new IllegalArgumentException();
   412         } else {
   413             Object[] arr = (Object[])array;
   414             arr[index] = value;
   415         }
   416     }
   417 
   418     /**
   419      * Sets the value of the indexed component of the specified array
   420      * object to the specified {@code boolean} value.
   421      * @param array the array
   422      * @param index the index into the array
   423      * @param z the new value of the indexed component
   424      * @exception NullPointerException If the specified object argument
   425      * is null
   426      * @exception IllegalArgumentException If the specified object argument
   427      * is not an array, or if the specified value cannot be converted
   428      * to the underlying array's component type by an identity or a
   429      * primitive widening conversion
   430      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   431      * argument is negative, or if it is greater than or equal to
   432      * the length of the specified array
   433      * @see Array#set
   434      */
   435     public static native void setBoolean(Object array, int index, boolean z)
   436         throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
   437 
   438     /**
   439      * Sets the value of the indexed component of the specified array
   440      * object to the specified {@code byte} value.
   441      * @param array the array
   442      * @param index the index into the array
   443      * @param b the new value of the indexed component
   444      * @exception NullPointerException If the specified object argument
   445      * is null
   446      * @exception IllegalArgumentException If the specified object argument
   447      * is not an array, or if the specified value cannot be converted
   448      * to the underlying array's component type by an identity or a
   449      * primitive widening conversion
   450      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   451      * argument is negative, or if it is greater than or equal to
   452      * the length of the specified array
   453      * @see Array#set
   454      */
   455     public static void setByte(Object array, int index, byte b)
   456     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   457         Class<?> t = array.getClass().getComponentType();
   458         if (t == Byte.TYPE) {
   459             byte[] arr = (byte[]) array;
   460             arr[index] = b;
   461         } else {
   462             setShort(array, index, b);
   463         }
   464     }
   465 
   466     /**
   467      * Sets the value of the indexed component of the specified array
   468      * object to the specified {@code char} value.
   469      * @param array the array
   470      * @param index the index into the array
   471      * @param c the new value of the indexed component
   472      * @exception NullPointerException If the specified object argument
   473      * is null
   474      * @exception IllegalArgumentException If the specified object argument
   475      * is not an array, or if the specified value cannot be converted
   476      * to the underlying array's component type by an identity or a
   477      * primitive widening conversion
   478      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   479      * argument is negative, or if it is greater than or equal to
   480      * the length of the specified array
   481      * @see Array#set
   482      */
   483     public static native void setChar(Object array, int index, char c)
   484         throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
   485 
   486     /**
   487      * Sets the value of the indexed component of the specified array
   488      * object to the specified {@code short} value.
   489      * @param array the array
   490      * @param index the index into the array
   491      * @param s the new value of the indexed component
   492      * @exception NullPointerException If the specified object argument
   493      * is null
   494      * @exception IllegalArgumentException If the specified object argument
   495      * is not an array, or if the specified value cannot be converted
   496      * to the underlying array's component type by an identity or a
   497      * primitive widening conversion
   498      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   499      * argument is negative, or if it is greater than or equal to
   500      * the length of the specified array
   501      * @see Array#set
   502      */
   503     public static void setShort(Object array, int index, short s)
   504     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   505         Class<?> t = array.getClass().getComponentType();
   506         if (t == Short.TYPE) {
   507             short[] arr = (short[]) array;
   508             arr[index] = s;
   509         } else {
   510             setInt(array, index, s);
   511         }
   512         
   513     }
   514 
   515     /**
   516      * Sets the value of the indexed component of the specified array
   517      * object to the specified {@code int} value.
   518      * @param array the array
   519      * @param index the index into the array
   520      * @param i the new value of the indexed component
   521      * @exception NullPointerException If the specified object argument
   522      * is null
   523      * @exception IllegalArgumentException If the specified object argument
   524      * is not an array, or if the specified value cannot be converted
   525      * to the underlying array's component type by an identity or a
   526      * primitive widening conversion
   527      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   528      * argument is negative, or if it is greater than or equal to
   529      * the length of the specified array
   530      * @see Array#set
   531      */
   532     public static void setInt(Object array, int index, int i)
   533     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   534         Class<?> t = array.getClass().getComponentType();
   535         if (t == Integer.TYPE) {
   536             long[] arr = (long[]) array;
   537             arr[index] = i;
   538         } else {
   539             setLong(array, index, i);
   540         }
   541     }
   542 
   543     /**
   544      * Sets the value of the indexed component of the specified array
   545      * object to the specified {@code long} value.
   546      * @param array the array
   547      * @param index the index into the array
   548      * @param l the new value of the indexed component
   549      * @exception NullPointerException If the specified object argument
   550      * is null
   551      * @exception IllegalArgumentException If the specified object argument
   552      * is not an array, or if the specified value cannot be converted
   553      * to the underlying array's component type by an identity or a
   554      * primitive widening conversion
   555      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   556      * argument is negative, or if it is greater than or equal to
   557      * the length of the specified array
   558      * @see Array#set
   559      */
   560     public static void setLong(Object array, int index, long l)
   561     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   562         Class<?> t = array.getClass().getComponentType();
   563         if (t == Long.TYPE) {
   564             long[] arr = (long[]) array;
   565             arr[index] = l;
   566         } else {
   567             setFloat(array, index, l);
   568         }
   569     }
   570 
   571     /**
   572      * Sets the value of the indexed component of the specified array
   573      * object to the specified {@code float} value.
   574      * @param array the array
   575      * @param index the index into the array
   576      * @param f the new value of the indexed component
   577      * @exception NullPointerException If the specified object argument
   578      * is null
   579      * @exception IllegalArgumentException If the specified object argument
   580      * is not an array, or if the specified value cannot be converted
   581      * to the underlying array's component type by an identity or a
   582      * primitive widening conversion
   583      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   584      * argument is negative, or if it is greater than or equal to
   585      * the length of the specified array
   586      * @see Array#set
   587      */
   588     public static void setFloat(Object array, int index, float f)
   589     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   590         Class<?> t = array.getClass().getComponentType();
   591         if (t == Float.TYPE) {
   592             float[] arr = (float[])array;
   593             arr[index] = f;
   594         } else {
   595             setDouble(array, index, f);
   596         }
   597     }
   598 
   599     /**
   600      * Sets the value of the indexed component of the specified array
   601      * object to the specified {@code double} value.
   602      * @param array the array
   603      * @param index the index into the array
   604      * @param d the new value of the indexed component
   605      * @exception NullPointerException If the specified object argument
   606      * is null
   607      * @exception IllegalArgumentException If the specified object argument
   608      * is not an array, or if the specified value cannot be converted
   609      * to the underlying array's component type by an identity or a
   610      * primitive widening conversion
   611      * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
   612      * argument is negative, or if it is greater than or equal to
   613      * the length of the specified array
   614      * @see Array#set
   615      */
   616     public static void setDouble(Object array, int index, double d)
   617     throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
   618         Class<?> t = array.getClass().getComponentType();
   619         if (t == Double.TYPE) {
   620             double[] arr = (double[])array;
   621             arr[index] = d;
   622         } else {
   623             throw new IllegalArgumentException("argument type mismatch");
   624         }
   625     }
   626 
   627     /*
   628      * Private
   629      */
   630 
   631     @JavaScriptBody(args = { "primitive", "sig", "length" }, body =
   632           "var arr = new Array(length);\n"
   633         + "var value = primitive ? 0 : null;\n"
   634         + "for(var i = 0; i < length; i++) arr[i] = value;\n"
   635         + "arr.jvmName = sig;\n"
   636         + "return arr;"
   637     )
   638     private static native Object newArray(boolean primitive, String sig, int length);
   639 
   640     private static Object multiNewArray(String sig, int[] dims, int index)
   641     throws IllegalArgumentException, NegativeArraySizeException {
   642         if (dims.length == index + 1) {
   643             return newArray(sig.length() == 2, sig, dims[index]);
   644         }
   645         Object[] arr = (Object[]) newArray(false, sig, dims[index]);
   646         String compsig = sig.substring(1);
   647         for (int i = 0; i < arr.length; i++) {
   648             arr[i] = multiNewArray(compsig, dims, index + 1);
   649         }
   650         return arr;
   651     }
   652 }