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 /**
29 * The {@code Array} class provides static methods to dynamically create and
30 * access Java arrays.
31 *
32 * <p>{@code Array} permits widening conversions to occur during a get or set
33 * operation, but throws an {@code IllegalArgumentException} if a narrowing
34 * conversion would occur.
35 *
36 * @author Nakul Saraiya
37 */
38 public final
39 class Array {
40
41 /**
42 * Constructor. Class Array is not instantiable.
43 */
44 private Array() {}
45
46 /**
47 * Creates a new array with the specified component type and
102 * @exception IllegalArgumentException if the specified {@code dimensions}
103 * argument is a zero-dimensional array, if componentType is {@link
104 * Void#TYPE}, or if the number of dimensions of the requested array
105 * instance exceed 255.
106 * @exception NegativeArraySizeException if any of the components in
107 * the specified {@code dimensions} argument is negative.
108 */
109 public static Object newInstance(Class<?> componentType, int... dimensions)
110 throws IllegalArgumentException, NegativeArraySizeException {
111 return multiNewArray(componentType, dimensions);
112 }
113
114 /**
115 * Returns the length of the specified array object, as an {@code int}.
116 *
117 * @param array the array
118 * @return the length of the array
119 * @exception IllegalArgumentException if the object argument is not
120 * an array
121 */
122 public static native int getLength(Object array)
123 throws IllegalArgumentException;
124
125 /**
126 * Returns the value of the indexed component in the specified
127 * array object. The value is automatically wrapped in an object
128 * if it has a primitive type.
129 *
130 * @param array the array
131 * @param index the index
132 * @return the (possibly wrapped) value of the indexed component in
133 * the specified array
134 * @exception NullPointerException If the specified object is null
135 * @exception IllegalArgumentException If the specified object is not
136 * an array
137 * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
138 * argument is negative, or if it is greater than or equal to the
139 * length of the specified array
140 */
141 public static native Object get(Object array, int index)
460 * @param index the index into the array
461 * @param d the new value of the indexed component
462 * @exception NullPointerException If the specified object argument
463 * is null
464 * @exception IllegalArgumentException If the specified object argument
465 * is not an array, or if the specified value cannot be converted
466 * to the underlying array's component type by an identity or a
467 * primitive widening conversion
468 * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
469 * argument is negative, or if it is greater than or equal to
470 * the length of the specified array
471 * @see Array#set
472 */
473 public static native void setDouble(Object array, int index, double d)
474 throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
475
476 /*
477 * Private
478 */
479
480 private static native Object newArray(Class<?> componentType, int length)
481 throws NegativeArraySizeException;
482
483 private static native Object multiNewArray(Class<?> componentType,
484 int[] dimensions)
485 throws IllegalArgumentException, NegativeArraySizeException;
486
487
488 }
|
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 jdk.internal.HotSpotIntrinsicCandidate;
29
30 /**
31 * The {@code Array} class provides static methods to dynamically create and
32 * access Java arrays.
33 *
34 * <p>{@code Array} permits widening conversions to occur during a get or set
35 * operation, but throws an {@code IllegalArgumentException} if a narrowing
36 * conversion would occur.
37 *
38 * @author Nakul Saraiya
39 */
40 public final
41 class Array {
42
43 /**
44 * Constructor. Class Array is not instantiable.
45 */
46 private Array() {}
47
48 /**
49 * Creates a new array with the specified component type and
104 * @exception IllegalArgumentException if the specified {@code dimensions}
105 * argument is a zero-dimensional array, if componentType is {@link
106 * Void#TYPE}, or if the number of dimensions of the requested array
107 * instance exceed 255.
108 * @exception NegativeArraySizeException if any of the components in
109 * the specified {@code dimensions} argument is negative.
110 */
111 public static Object newInstance(Class<?> componentType, int... dimensions)
112 throws IllegalArgumentException, NegativeArraySizeException {
113 return multiNewArray(componentType, dimensions);
114 }
115
116 /**
117 * Returns the length of the specified array object, as an {@code int}.
118 *
119 * @param array the array
120 * @return the length of the array
121 * @exception IllegalArgumentException if the object argument is not
122 * an array
123 */
124 @HotSpotIntrinsicCandidate
125 public static native int getLength(Object array)
126 throws IllegalArgumentException;
127
128 /**
129 * Returns the value of the indexed component in the specified
130 * array object. The value is automatically wrapped in an object
131 * if it has a primitive type.
132 *
133 * @param array the array
134 * @param index the index
135 * @return the (possibly wrapped) value of the indexed component in
136 * the specified array
137 * @exception NullPointerException If the specified object is null
138 * @exception IllegalArgumentException If the specified object is not
139 * an array
140 * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
141 * argument is negative, or if it is greater than or equal to the
142 * length of the specified array
143 */
144 public static native Object get(Object array, int index)
463 * @param index the index into the array
464 * @param d the new value of the indexed component
465 * @exception NullPointerException If the specified object argument
466 * is null
467 * @exception IllegalArgumentException If the specified object argument
468 * is not an array, or if the specified value cannot be converted
469 * to the underlying array's component type by an identity or a
470 * primitive widening conversion
471 * @exception ArrayIndexOutOfBoundsException If the specified {@code index}
472 * argument is negative, or if it is greater than or equal to
473 * the length of the specified array
474 * @see Array#set
475 */
476 public static native void setDouble(Object array, int index, double d)
477 throws IllegalArgumentException, ArrayIndexOutOfBoundsException;
478
479 /*
480 * Private
481 */
482
483 @HotSpotIntrinsicCandidate
484 private static native Object newArray(Class<?> componentType, int length)
485 throws NegativeArraySizeException;
486
487 private static native Object multiNewArray(Class<?> componentType,
488 int[] dimensions)
489 throws IllegalArgumentException, NegativeArraySizeException;
490
491
492 }
|