2003 * by a Java casting conversion (JLS 5.5) on the primitive value,
2004 * possibly followed by a conversion from byte to boolean by testing
2005 * the low-order bit.
2006 * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive,
2007 * and if the reference is null at runtime, a zero value is introduced.
2008 * </ul>
2009 * @param target the method handle to invoke after arguments are retyped
2010 * @param newType the expected type of the new method handle
2011 * @return a method handle which delegates to the target after performing
2012 * any necessary argument conversions, and arranges for any
2013 * necessary return value conversions
2014 * @throws NullPointerException if either argument is null
2015 * @throws WrongMethodTypeException if the conversion cannot be made
2016 * @see MethodHandle#asType
2017 */
2018 public static
2019 MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
2020 if (!target.type().isCastableTo(newType)) {
2021 throw new WrongMethodTypeException("cannot explicitly cast "+target+" to "+newType);
2022 }
2023 return MethodHandleImpl.makePairwiseConvert(target, newType, 2);
2024 }
2025
2026 /**
2027 * Produces a method handle which adapts the calling sequence of the
2028 * given method handle to a new type, by reordering the arguments.
2029 * The resulting method handle is guaranteed to report a type
2030 * which is equal to the desired new type.
2031 * <p>
2032 * The given array controls the reordering.
2033 * Call {@code #I} the number of incoming parameters (the value
2034 * {@code newType.parameterCount()}, and call {@code #O} the number
2035 * of outgoing parameters (the value {@code target.type().parameterCount()}).
2036 * Then the length of the reordering array must be {@code #O},
2037 * and each element must be a non-negative number less than {@code #I}.
2038 * For every {@code N} less than {@code #O}, the {@code N}-th
2039 * outgoing argument will be taken from the {@code I}-th incoming
2040 * argument, where {@code I} is {@code reorder[N]}.
2041 * <p>
2042 * No argument or return value conversions are applied.
2043 * The type of each incoming argument, as determined by {@code newType},
|
2003 * by a Java casting conversion (JLS 5.5) on the primitive value,
2004 * possibly followed by a conversion from byte to boolean by testing
2005 * the low-order bit.
2006 * <li>If <em>T0</em> is a reference and <em>T1</em> a primitive,
2007 * and if the reference is null at runtime, a zero value is introduced.
2008 * </ul>
2009 * @param target the method handle to invoke after arguments are retyped
2010 * @param newType the expected type of the new method handle
2011 * @return a method handle which delegates to the target after performing
2012 * any necessary argument conversions, and arranges for any
2013 * necessary return value conversions
2014 * @throws NullPointerException if either argument is null
2015 * @throws WrongMethodTypeException if the conversion cannot be made
2016 * @see MethodHandle#asType
2017 */
2018 public static
2019 MethodHandle explicitCastArguments(MethodHandle target, MethodType newType) {
2020 if (!target.type().isCastableTo(newType)) {
2021 throw new WrongMethodTypeException("cannot explicitly cast "+target+" to "+newType);
2022 }
2023 return MethodHandleImpl.makePairwiseConvert(target, newType, false);
2024 }
2025
2026 /**
2027 * Produces a method handle which adapts the calling sequence of the
2028 * given method handle to a new type, by reordering the arguments.
2029 * The resulting method handle is guaranteed to report a type
2030 * which is equal to the desired new type.
2031 * <p>
2032 * The given array controls the reordering.
2033 * Call {@code #I} the number of incoming parameters (the value
2034 * {@code newType.parameterCount()}, and call {@code #O} the number
2035 * of outgoing parameters (the value {@code target.type().parameterCount()}).
2036 * Then the length of the reordering array must be {@code #O},
2037 * and each element must be a non-negative number less than {@code #I}.
2038 * For every {@code N} less than {@code #O}, the {@code N}-th
2039 * outgoing argument will be taken from the {@code I}-th incoming
2040 * argument, where {@code I} is {@code reorder[N]}.
2041 * <p>
2042 * No argument or return value conversions are applied.
2043 * The type of each incoming argument, as determined by {@code newType},
|