< prev index next >
src/java.base/share/classes/java/lang/invoke/MethodHandles.java
Print this page
*** 2512,2529 ****
static ConcurrentHashMap<MemberName, DirectMethodHandle> LOOKASIDE_TABLE = new ConcurrentHashMap<>();
}
/**
! * Produces a method handle constructing arrays of a desired type.
* The return type of the method handle will be the array type.
* The type of its sole argument will be {@code int}, which specifies the size of the array.
* @param arrayClass an array type
* @return a method handle which can create arrays of the given type
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if {@code arrayClass} is not an array type
* @see java.lang.reflect.Array#newInstance(Class, int)
* @since 9
*/
public static
MethodHandle arrayConstructor(Class<?> arrayClass) throws IllegalArgumentException {
if (!arrayClass.isArray()) {
--- 2512,2535 ----
static ConcurrentHashMap<MemberName, DirectMethodHandle> LOOKASIDE_TABLE = new ConcurrentHashMap<>();
}
/**
! * Produces a method handle constructing arrays of a desired type,
! * as if by the {@code anewarray} bytecode.
* The return type of the method handle will be the array type.
* The type of its sole argument will be {@code int}, which specifies the size of the array.
+ *
+ * <p> If the returned method handle is invoked with a negative
+ * array size, {@code NegativeArraySizeException} will be thrown.
+ *
* @param arrayClass an array type
* @return a method handle which can create arrays of the given type
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if {@code arrayClass} is not an array type
* @see java.lang.reflect.Array#newInstance(Class, int)
+ * @jvms 6.5 {@code anewarray} Instruction
* @since 9
*/
public static
MethodHandle arrayConstructor(Class<?> arrayClass) throws IllegalArgumentException {
if (!arrayClass.isArray()) {
*** 2533,2580 ****
bindTo(arrayClass.getComponentType());
return ani.asType(ani.type().changeReturnType(arrayClass));
}
/**
! * Produces a method handle returning the length of an array.
* The type of the method handle will have {@code int} as return type,
* and its sole argument will be the array type.
* @param arrayClass an array type
* @return a method handle which can retrieve the length of an array of the given array type
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if arrayClass is not an array type
* @since 9
*/
public static
MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.LENGTH);
}
/**
! * Produces a method handle giving read access to elements of an array.
* The type of the method handle will have a return type of the array's
* element type. Its first argument will be the array type,
* and the second will be {@code int}.
* @param arrayClass an array type
* @return a method handle which can load values from the given array type
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
*/
public static
MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
}
/**
! * Produces a method handle giving write access to elements of an array.
* The type of the method handle will have a void return type.
* Its last argument will be the array's element type.
* The first and second arguments will be the array type and int.
* @param arrayClass the class of an array
* @return a method handle which can store values into the array type
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
*/
public static
MethodHandle arrayElementSetter(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.SET);
}
--- 2539,2612 ----
bindTo(arrayClass.getComponentType());
return ani.asType(ani.type().changeReturnType(arrayClass));
}
/**
! * Produces a method handle returning the length of an array,
! * as if by the {@code arrayLength} bytecode.
* The type of the method handle will have {@code int} as return type,
* and its sole argument will be the array type.
+ *
+ * <p> If the returned method handle is invoked with a {@code null}
+ * array reference, {@code NullPointerPointer} will be thrown.
+ *
* @param arrayClass an array type
* @return a method handle which can retrieve the length of an array of the given array type
* @throws NullPointerException if the argument is {@code null}
* @throws IllegalArgumentException if arrayClass is not an array type
+ * @jvms 6.5 {@code arrayLength} Instruction
* @since 9
*/
public static
MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.LENGTH);
}
/**
! * Produces a method handle giving read access to elements of an array,
! * as if by the {@code aaload} bytecode.
* The type of the method handle will have a return type of the array's
* element type. Its first argument will be the array type,
* and the second will be {@code int}.
+ *
+ * <p> When the returned method handle is invoked,
+ * the array reference and array index are checked.
+ * {@code NullPointerPointer} will be thrown if the array reference
+ * is {@code null} and {@code ArrayIndexOutOfBoundsException} will be
+ * thrown if the index is negative or if it is greater than or equal to
+ * the length of the array.
+ *
* @param arrayClass an array type
* @return a method handle which can load values from the given array type
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
+ * @jvms 6.5 {@code aaload} Instruction
*/
public static
MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
}
/**
! * Produces a method handle giving write access to elements of an array,
! * as if by the {@code astore} bytecode.
* The type of the method handle will have a void return type.
* Its last argument will be the array's element type.
* The first and second arguments will be the array type and int.
+ *
+ * <p> When the returned method handle is invoked,
+ * the array reference and array index are checked.
+ * {@code NullPointerPointer} will be thrown if the array reference
+ * is {@code null} and {@code ArrayIndexOutOfBoundsException} will be
+ * thrown if the index is negative or if it is greater than or equal to
+ * the length of the array.
+ *
* @param arrayClass the class of an array
* @return a method handle which can store values into the array type
* @throws NullPointerException if the argument is null
* @throws IllegalArgumentException if arrayClass is not an array type
+ * @jvms 6.5 {@code aastore} Instruction
*/
public static
MethodHandle arrayElementSetter(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.SET);
}
*** 2601,2610 ****
--- 2633,2650 ----
* <p>
* If the component type is {@code float} or {@code double} then numeric
* and atomic update access modes compare values using their bitwise
* representation (see {@link Float#floatToRawIntBits} and
* {@link Double#doubleToRawLongBits}, respectively).
+ *
+ * <p> When the returned {@code VarHandle} is invoked,
+ * the array reference and array index are checked.
+ * {@code NullPointerPointer} will be thrown if the array reference
+ * is {@code null} and {@code ArrayIndexOutOfBoundsException} will be
+ * thrown if the index is negative or if it is greater than or equal to
+ * the length of the array.
+ *
* @apiNote
* Bitwise comparison of {@code float} values or {@code double} values,
* as performed by the numeric and atomic update access modes, differ
* from the primitive {@code ==} operator and the {@link Float#equals}
* and {@link Double#equals} methods, specifically with respect to
< prev index next >