< prev index next >

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

Print this page




1378          *
1379          * @param refc the class or interface from which the method is accessed
1380          * @param name the name of the method (which must not be "&lt;init&gt;")
1381          * @param type the type of the method, with the receiver argument omitted
1382          * @param specialCaller the proposed calling class to perform the {@code invokespecial}
1383          * @return the desired method handle
1384          * @throws NoSuchMethodException if the method does not exist
1385          * @throws IllegalAccessException if access checking fails,
1386          *                                or if the method is {@code static},
1387          *                                or if the method's variable arity modifier bit
1388          *                                is set and {@code asVarargsCollector} fails
1389          * @exception SecurityException if a security manager is present and it
1390          *                              <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
1391          * @throws NullPointerException if any argument is null
1392          */
1393         public MethodHandle findSpecial(Class<?> refc, String name, MethodType type,
1394                                         Class<?> specialCaller) throws NoSuchMethodException, IllegalAccessException {
1395             checkSpecialCaller(specialCaller, refc);
1396             Lookup specialLookup = this.in(specialCaller);
1397             MemberName method = specialLookup.resolveOrFail(REF_invokeSpecial, refc, name, type);
1398             Class<?> callerCls = findBoundCallerClass(method);
1399             boolean restrict = !(method.isPrivate() && Reflection.areNestMates(specialCaller, refc));
1400 
1401             if (restrict)
1402                 return specialLookup.getDirectMethod(REF_invokeSpecial, refc, method, callerCls);
1403             else
1404                 return specialLookup.getDirectMethodNoRestrictInvokeSpecial(refc, method, callerCls);
1405         }
1406 
1407         /**
1408          * Produces a method handle giving read access to a non-static field.
1409          * The type of the method handle will have a return type of the field's
1410          * value type.
1411          * The method handle's single argument will be the instance containing
1412          * the field.
1413          * Access checking is performed immediately on behalf of the lookup class.
1414          * @param refc the class or interface from which the method is accessed
1415          * @param name the field's name
1416          * @param type the field's type
1417          * @return a method handle which can load values from the field
1418          * @throws NoSuchFieldException if the field does not exist
1419          * @throws IllegalAccessException if access checking fails, or if the field is {@code static}
1420          * @exception SecurityException if a security manager is present and it
1421          *                              <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
1422          * @throws NullPointerException if any argument is null
1423          * @see #findVarHandle(Class, String, Class)
1424          */




1378          *
1379          * @param refc the class or interface from which the method is accessed
1380          * @param name the name of the method (which must not be "&lt;init&gt;")
1381          * @param type the type of the method, with the receiver argument omitted
1382          * @param specialCaller the proposed calling class to perform the {@code invokespecial}
1383          * @return the desired method handle
1384          * @throws NoSuchMethodException if the method does not exist
1385          * @throws IllegalAccessException if access checking fails,
1386          *                                or if the method is {@code static},
1387          *                                or if the method's variable arity modifier bit
1388          *                                is set and {@code asVarargsCollector} fails
1389          * @exception SecurityException if a security manager is present and it
1390          *                              <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
1391          * @throws NullPointerException if any argument is null
1392          */
1393         public MethodHandle findSpecial(Class<?> refc, String name, MethodType type,
1394                                         Class<?> specialCaller) throws NoSuchMethodException, IllegalAccessException {
1395             checkSpecialCaller(specialCaller, refc);
1396             Lookup specialLookup = this.in(specialCaller);
1397             MemberName method = specialLookup.resolveOrFail(REF_invokeSpecial, refc, name, type);
1398             return specialLookup.getDirectMethod(REF_invokeSpecial, refc, method, findBoundCallerClass(method));






1399         }
1400 
1401         /**
1402          * Produces a method handle giving read access to a non-static field.
1403          * The type of the method handle will have a return type of the field's
1404          * value type.
1405          * The method handle's single argument will be the instance containing
1406          * the field.
1407          * Access checking is performed immediately on behalf of the lookup class.
1408          * @param refc the class or interface from which the method is accessed
1409          * @param name the field's name
1410          * @param type the field's type
1411          * @return a method handle which can load values from the field
1412          * @throws NoSuchFieldException if the field does not exist
1413          * @throws IllegalAccessException if access checking fails, or if the field is {@code static}
1414          * @exception SecurityException if a security manager is present and it
1415          *                              <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>
1416          * @throws NullPointerException if any argument is null
1417          * @see #findVarHandle(Class, String, Class)
1418          */


< prev index next >