< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandles.java

Print this page




 360      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#findConstructor lookup.findConstructor(C.class,MT)}</th>
 361      *     <td>{@code C(A*);}</td><td>{@code new C(arg*);}</td>
 362      * </tr>
 363      * <tr>
 364      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter lookup.unreflectGetter(aField)}</th>
 365      *     <td>({@code static})?<br>{@code FT f;}</td><td>{@code (FT) aField.get(thisOrNull);}</td>
 366      * </tr>
 367      * <tr>
 368      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter lookup.unreflectSetter(aField)}</th>
 369      *     <td>({@code static})?<br>{@code FT f;}</td><td>{@code aField.set(thisOrNull, arg);}</td>
 370      * </tr>
 371      * <tr>
 372      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflect lookup.unreflect(aMethod)}</th>
 373      *     <td>({@code static})?<br>{@code T m(A*);}</td><td>{@code (T) aMethod.invoke(thisOrNull, arg*);}</td>
 374      * </tr>
 375      * <tr>
 376      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor lookup.unreflectConstructor(aConstructor)}</th>
 377      *     <td>{@code C(A*);}</td><td>{@code (C) aConstructor.newInstance(arg*);}</td>
 378      * </tr>
 379      * <tr>
 380      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflect lookup.unreflect(aMethod)}</th>
 381      *     <td>({@code static})?<br>{@code T m(A*);}</td><td>{@code (T) aMethod.invoke(thisOrNull, arg*);}</td>
 382      * </tr>
 383      * <tr>
 384      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#findClass lookup.findClass("C")}</th>
 385      *     <td>{@code class C { ... }}</td><td>{@code C.class;}</td>
 386      * </tr>
 387      * </tbody>
 388      * </table>
 389      *
 390      * Here, the type {@code C} is the class or interface being searched for a member,
 391      * documented as a parameter named {@code refc} in the lookup methods.
 392      * The method type {@code MT} is composed from the return type {@code T}
 393      * and the sequence of argument types {@code A*}.
 394      * The constructor also has a sequence of argument types {@code A*} and
 395      * is deemed to return the newly-created object of type {@code C}.
 396      * Both {@code MT} and the field type {@code FT} are documented as a parameter named {@code type}.
 397      * The formal parameter {@code this} stands for the self-reference of type {@code C};
 398      * if it is present, it is always the leading argument to the method handle invocation.
 399      * (In the case of some {@code protected} members, {@code this} may be
 400      * restricted in type to the lookup class; see below.)
 401      * The name {@code arg} stands for all the other method handle arguments.


2480          * <p>
2481          * Before method resolution,
2482          * if the explicitly specified caller class is not identical with the
2483          * lookup class, or if this lookup object does not have
2484          * <a href="MethodHandles.Lookup.html#privacc">private access</a>
2485          * privileges, the access fails.
2486          * <p>
2487          * The returned method handle will have
2488          * {@linkplain MethodHandle#asVarargsCollector variable arity} if and only if
2489          * the method's variable arity modifier bit ({@code 0x0080}) is set.
2490          * @param m the reflected method
2491          * @param specialCaller the class nominally calling the method
2492          * @return a method handle which can invoke the reflected method
2493          * @throws IllegalAccessException if access checking fails,
2494          *                                or if the method is {@code static},
2495          *                                or if the method's variable arity modifier bit
2496          *                                is set and {@code asVarargsCollector} fails
2497          * @throws NullPointerException if any argument is null
2498          */
2499         public MethodHandle unreflectSpecial(Method m, Class<?> specialCaller) throws IllegalAccessException {
2500             checkSpecialCaller(specialCaller, null);
2501             Lookup specialLookup = this.in(specialCaller);
2502             MemberName method = new MemberName(m, true);
2503             assert(method.isMethod());
2504             // ignore m.isAccessible:  this is a new kind of access
2505             return specialLookup.getDirectMethodNoSecurityManager(REF_invokeSpecial, method.getDeclaringClass(), method, findBoundCallerClass(method));
2506         }
2507 
2508         /**
2509          * Produces a method handle for a reflected constructor.
2510          * The type of the method handle will be that of the constructor,
2511          * with the return type changed to the declaring class.
2512          * The method handle will perform a {@code newInstance} operation,
2513          * creating a new instance of the constructor's class on the
2514          * arguments passed to the method handle.
2515          * <p>
2516          * If the constructor's {@code accessible} flag is not set,
2517          * access checking is performed immediately on behalf of the lookup class.
2518          * <p>
2519          * The returned method handle will have
2520          * {@linkplain MethodHandle#asVarargsCollector variable arity} if and only if




 360      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#findConstructor lookup.findConstructor(C.class,MT)}</th>
 361      *     <td>{@code C(A*);}</td><td>{@code new C(arg*);}</td>
 362      * </tr>
 363      * <tr>
 364      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter lookup.unreflectGetter(aField)}</th>
 365      *     <td>({@code static})?<br>{@code FT f;}</td><td>{@code (FT) aField.get(thisOrNull);}</td>
 366      * </tr>
 367      * <tr>
 368      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter lookup.unreflectSetter(aField)}</th>
 369      *     <td>({@code static})?<br>{@code FT f;}</td><td>{@code aField.set(thisOrNull, arg);}</td>
 370      * </tr>
 371      * <tr>
 372      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflect lookup.unreflect(aMethod)}</th>
 373      *     <td>({@code static})?<br>{@code T m(A*);}</td><td>{@code (T) aMethod.invoke(thisOrNull, arg*);}</td>
 374      * </tr>
 375      * <tr>
 376      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor lookup.unreflectConstructor(aConstructor)}</th>
 377      *     <td>{@code C(A*);}</td><td>{@code (C) aConstructor.newInstance(arg*);}</td>
 378      * </tr>
 379      * <tr>
 380      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#unreflectSpecial lookup.unreflectSpecial(aMethod,this.class)}</th>
 381      *     <td>{@code T m(A*);}</td><td>{@code (T) aMethod.invoke(this, arg*);}</td>
 382      * </tr>
 383      * <tr>
 384      *     <th scope="row">{@link java.lang.invoke.MethodHandles.Lookup#findClass lookup.findClass("C")}</th>
 385      *     <td>{@code class C { ... }}</td><td>{@code C.class;}</td>
 386      * </tr>
 387      * </tbody>
 388      * </table>
 389      *
 390      * Here, the type {@code C} is the class or interface being searched for a member,
 391      * documented as a parameter named {@code refc} in the lookup methods.
 392      * The method type {@code MT} is composed from the return type {@code T}
 393      * and the sequence of argument types {@code A*}.
 394      * The constructor also has a sequence of argument types {@code A*} and
 395      * is deemed to return the newly-created object of type {@code C}.
 396      * Both {@code MT} and the field type {@code FT} are documented as a parameter named {@code type}.
 397      * The formal parameter {@code this} stands for the self-reference of type {@code C};
 398      * if it is present, it is always the leading argument to the method handle invocation.
 399      * (In the case of some {@code protected} members, {@code this} may be
 400      * restricted in type to the lookup class; see below.)
 401      * The name {@code arg} stands for all the other method handle arguments.


2480          * <p>
2481          * Before method resolution,
2482          * if the explicitly specified caller class is not identical with the
2483          * lookup class, or if this lookup object does not have
2484          * <a href="MethodHandles.Lookup.html#privacc">private access</a>
2485          * privileges, the access fails.
2486          * <p>
2487          * The returned method handle will have
2488          * {@linkplain MethodHandle#asVarargsCollector variable arity} if and only if
2489          * the method's variable arity modifier bit ({@code 0x0080}) is set.
2490          * @param m the reflected method
2491          * @param specialCaller the class nominally calling the method
2492          * @return a method handle which can invoke the reflected method
2493          * @throws IllegalAccessException if access checking fails,
2494          *                                or if the method is {@code static},
2495          *                                or if the method's variable arity modifier bit
2496          *                                is set and {@code asVarargsCollector} fails
2497          * @throws NullPointerException if any argument is null
2498          */
2499         public MethodHandle unreflectSpecial(Method m, Class<?> specialCaller) throws IllegalAccessException {
2500             checkSpecialCaller(specialCaller, m.getDeclaringClass());
2501             Lookup specialLookup = this.in(specialCaller);
2502             MemberName method = new MemberName(m, true);
2503             assert(method.isMethod());
2504             // ignore m.isAccessible:  this is a new kind of access
2505             return specialLookup.getDirectMethodNoSecurityManager(REF_invokeSpecial, method.getDeclaringClass(), method, findBoundCallerClass(method));
2506         }
2507 
2508         /**
2509          * Produces a method handle for a reflected constructor.
2510          * The type of the method handle will be that of the constructor,
2511          * with the return type changed to the declaring class.
2512          * The method handle will perform a {@code newInstance} operation,
2513          * creating a new instance of the constructor's class on the
2514          * arguments passed to the method handle.
2515          * <p>
2516          * If the constructor's {@code accessible} flag is not set,
2517          * access checking is performed immediately on behalf of the lookup class.
2518          * <p>
2519          * The returned method handle will have
2520          * {@linkplain MethodHandle#asVarargsCollector variable arity} if and only if


< prev index next >