8156915: introduce MethodHandle factory for array length

Reviewed-by: sundar
This commit is contained in:
Michael Haupt 2016-05-18 10:42:29 +02:00
parent 2bb441c404
commit c4976196f5
4 changed files with 197 additions and 33 deletions

View file

@ -2244,6 +2244,20 @@ return mh1;
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
*/
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
@ -2256,7 +2270,7 @@ return mh1;
*/
public static
MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, false);
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
}
/**
@ -2271,7 +2285,7 @@ return mh1;
*/
public static
MethodHandle arrayElementSetter(Class<?> arrayClass) throws IllegalArgumentException {
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, true);
return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.SET);
}
/**