< prev index next >

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

Print this page




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




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 >