mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8156915: introduce MethodHandle factory for array length
Reviewed-by: sundar
This commit is contained in:
parent
2bb441c404
commit
c4976196f5
4 changed files with 197 additions and 33 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue