src/java.base/share/classes/java/lang/invoke/ConstantBootstraps.java
changeset 49242 d2a2a80774e8
parent 48990 9c006936068b
child 49576 535498e7602f
equal deleted inserted replaced
49241:de4b3a04feae 49242:d2a2a80774e8
   102      * Returns an {@code enum} constant of the type specified by {@code type}
   102      * Returns an {@code enum} constant of the type specified by {@code type}
   103      * with the name specified by {@code name}.
   103      * with the name specified by {@code name}.
   104      *
   104      *
   105      * @param lookup the lookup context describing the class performing the
   105      * @param lookup the lookup context describing the class performing the
   106      * operation (normally stacked by the JVM)
   106      * operation (normally stacked by the JVM)
       
   107      * @param name the name of the constant to return, which must exactly match
       
   108      * an enum constant in the specified type.
   107      * @param type the {@code Class} object describing the enum type for which
   109      * @param type the {@code Class} object describing the enum type for which
   108      * a constant is to be returned
   110      * a constant is to be returned
   109      * @param name the name of the constant to return, which must exactly match
       
   110      * an enum constant in the specified type.
       
   111      * @param <E> The enum type for which a constant value is to be returned
   111      * @param <E> The enum type for which a constant value is to be returned
   112      * @return the enum constant of the specified enum type with the
   112      * @return the enum constant of the specified enum type with the
   113      * specified name
   113      * specified name
   114      * @throws IllegalAccessError if the declaring class or the field is not
   114      * @throws IllegalAccessError if the declaring class or the field is not
   115      * accessible to the class performing the operation
   115      * accessible to the class performing the operation
   206 
   206 
   207 
   207 
   208     /**
   208     /**
   209      * Returns the result of invoking a method handle with the provided
   209      * Returns the result of invoking a method handle with the provided
   210      * arguments.
   210      * arguments.
       
   211      * <p>
       
   212      * This method behaves as if the method handle to be invoked is the result
       
   213      * of adapting the given method handle, via {@link MethodHandle#asType}, to
       
   214      * adjust the return type to the desired type.
   211      *
   215      *
   212      * @param lookup unused
   216      * @param lookup unused
   213      * @param name unused
   217      * @param name unused
   214      * @param type the type of the value to be returned, which must be
   218      * @param type the desired type of the value to be returned, which must be
   215      * compatible with the return type of the method handle
   219      * compatible with the return type of the method handle
   216      * @param handle the method handle to be invoked
   220      * @param handle the method handle to be invoked
   217      * @param args the arguments to pass to the method handle, as if with
   221      * @param args the arguments to pass to the method handle, as if with
   218      * {@link MethodHandle#invokeWithArguments}.  Each argument may be
   222      * {@link MethodHandle#invokeWithArguments}.  Each argument may be
   219      * {@code null}.
   223      * {@code null}.
   220      * @return the result of invoking the method handle
   224      * @return the result of invoking the method handle
   221      * @throws WrongMethodTypeException if the handle's return type cannot be
   225      * @throws WrongMethodTypeException if the handle's method type cannot be
   222      * adjusted to the desired type
   226      * adjusted to take the given number of arguments, or if the handle's return
   223      * @throws ClassCastException if an argument cannot be converted by
   227      * type cannot be adjusted to the desired type
   224      * reference casting
   228      * @throws ClassCastException if an argument or the result produced by
       
   229      * invoking the handle cannot be converted by reference casting
   225      * @throws Throwable anything thrown by the method handle invocation
   230      * @throws Throwable anything thrown by the method handle invocation
   226      */
   231      */
   227     public static Object invoke(MethodHandles.Lookup lookup, String name, Class<?> type,
   232     public static Object invoke(MethodHandles.Lookup lookup, String name, Class<?> type,
   228                                 MethodHandle handle, Object... args) throws Throwable {
   233                                 MethodHandle handle, Object... args) throws Throwable {
   229         requireNonNull(type);
   234         requireNonNull(type);