< prev index next >

src/java.base/share/classes/java/lang/reflect/Array.java

Print this page

        

*** 23,32 **** --- 23,33 ---- * questions. */ package java.lang.reflect; + import java.util.Objects; import jdk.internal.HotSpotIntrinsicCandidate; /** * The {@code Array} class provides static methods to dynamically create and * access Java arrays.
*** 140,151 **** * an array * @exception ArrayIndexOutOfBoundsException If the specified {@code index} * argument is negative, or if it is greater than or equal to the * length of the specified array */ ! public static native Object get(Object array, int index) ! throws IllegalArgumentException, ArrayIndexOutOfBoundsException; /** * Returns the value of the indexed component in the specified * array object, as a {@code boolean}. * --- 141,162 ---- * an array * @exception ArrayIndexOutOfBoundsException If the specified {@code index} * argument is negative, or if it is greater than or equal to the * length of the specified array */ ! public static Object get(Object array, int index) ! throws IllegalArgumentException, ArrayIndexOutOfBoundsException { ! Class<?> componentType = array.getClass().getComponentType(); ! if (componentType != null && !componentType.isPrimitive()) { ! Object[] objArray = (Object[]) array.getClass().cast(array); ! return objArray[index]; ! } else { ! return getReferenceOrPrimitive(array, index); ! } ! } ! ! private static native Object getReferenceOrPrimitive(Object array, int index); /** * Returns the value of the indexed component in the specified * array object, as a {@code boolean}. *
*** 312,323 **** * an unwrapping conversion fails * @exception ArrayIndexOutOfBoundsException If the specified {@code index} * argument is negative, or if it is greater than or equal to * the length of the specified array */ ! public static native void set(Object array, int index, Object value) ! throws IllegalArgumentException, ArrayIndexOutOfBoundsException; /** * Sets the value of the indexed component of the specified array * object to the specified {@code boolean} value. * @param array the array --- 323,344 ---- * an unwrapping conversion fails * @exception ArrayIndexOutOfBoundsException If the specified {@code index} * argument is negative, or if it is greater than or equal to * the length of the specified array */ ! public static void set(Object array, int index, Object value) ! throws IllegalArgumentException, ArrayIndexOutOfBoundsException { ! Class<?> componentType = array.getClass().getComponentType(); ! if (componentType != null && !componentType.isPrimitive()) { ! Object[] objArray = (Object[]) array.getClass().cast(array); ! objArray[index] = componentType.cast(value); ! } else { ! setReferenceOrPrimitive(array, index, value); ! } ! } ! ! private static native void setReferenceOrPrimitive(Object array, int index, Object value); /** * Sets the value of the indexed component of the specified array * object to the specified {@code boolean} value. * @param array the array
< prev index next >