2542 return compValue.newArray();
2543 } else {
2544 MethodHandle ani = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_Array_newInstance).
2545 bindTo(arrayClass.getComponentType());
2546 return ani.asType(ani.type().changeReturnType(arrayClass));
2547 }
2548 }
2549
2550 /**
2551 * Produces a method handle returning the length of an array.
2552 * The type of the method handle will have {@code int} as return type,
2553 * and its sole argument will be the array type.
2554 * @param arrayClass an array type
2555 * @return a method handle which can retrieve the length of an array of the given array type
2556 * @throws NullPointerException if the argument is {@code null}
2557 * @throws IllegalArgumentException if arrayClass is not an array type
2558 * @since 9
2559 */
2560 public static
2561 MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {
2562 return MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.LENGTH);
2563 }
2564
2565 /**
2566 * Produces a method handle giving read access to elements of an array.
2567 * The type of the method handle will have a return type of the array's
2568 * element type. Its first argument will be the array type,
2569 * and the second will be {@code int}.
2570 * @param arrayClass an array type
2571 * @return a method handle which can load values from the given array type
2572 * @throws NullPointerException if the argument is null
2573 * @throws IllegalArgumentException if arrayClass is not an array type
2574 */
2575 public static
2576 MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
2577 ValueType<?> compValue = valueComponent(arrayClass);
2578 return (compValue != null) ?
2579 compValue.arrayGetter() :
2580 MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
2581 }
2582
|
2542 return compValue.newArray();
2543 } else {
2544 MethodHandle ani = MethodHandleImpl.getConstantHandle(MethodHandleImpl.MH_Array_newInstance).
2545 bindTo(arrayClass.getComponentType());
2546 return ani.asType(ani.type().changeReturnType(arrayClass));
2547 }
2548 }
2549
2550 /**
2551 * Produces a method handle returning the length of an array.
2552 * The type of the method handle will have {@code int} as return type,
2553 * and its sole argument will be the array type.
2554 * @param arrayClass an array type
2555 * @return a method handle which can retrieve the length of an array of the given array type
2556 * @throws NullPointerException if the argument is {@code null}
2557 * @throws IllegalArgumentException if arrayClass is not an array type
2558 * @since 9
2559 */
2560 public static
2561 MethodHandle arrayLength(Class<?> arrayClass) throws IllegalArgumentException {
2562 ValueType<?> compValue = valueComponent(arrayClass);
2563 return (compValue != null) ?
2564 compValue.arrayLength() :
2565 MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.LENGTH);
2566 }
2567
2568 /**
2569 * Produces a method handle giving read access to elements of an array.
2570 * The type of the method handle will have a return type of the array's
2571 * element type. Its first argument will be the array type,
2572 * and the second will be {@code int}.
2573 * @param arrayClass an array type
2574 * @return a method handle which can load values from the given array type
2575 * @throws NullPointerException if the argument is null
2576 * @throws IllegalArgumentException if arrayClass is not an array type
2577 */
2578 public static
2579 MethodHandle arrayElementGetter(Class<?> arrayClass) throws IllegalArgumentException {
2580 ValueType<?> compValue = valueComponent(arrayClass);
2581 return (compValue != null) ?
2582 compValue.arrayGetter() :
2583 MethodHandleImpl.makeArrayElementAccessor(arrayClass, MethodHandleImpl.ArrayAccess.GET);
2584 }
2585
|