< prev index next >

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

Print this page




 206  * the untrusted code would be harmless.
 207  *
 208  * <h2>Method handle creation</h2>
 209  * Java code can create a method handle that directly accesses
 210  * any method, constructor, or field that is accessible to that code.
 211  * This is done via a reflective, capability-based API called
 212  * {@link java.lang.invoke.MethodHandles.Lookup MethodHandles.Lookup}.
 213  * For example, a static method handle can be obtained
 214  * from {@link java.lang.invoke.MethodHandles.Lookup#findStatic Lookup.findStatic}.
 215  * There are also conversion methods from Core Reflection API objects,
 216  * such as {@link java.lang.invoke.MethodHandles.Lookup#unreflect Lookup.unreflect}.
 217  * <p>
 218  * Like classes and strings, method handles that correspond to accessible
 219  * fields, methods, and constructors can also be represented directly
 220  * in a class file's constant pool as constants to be loaded by {@code ldc} bytecodes.
 221  * A new type of constant pool entry, {@code CONSTANT_MethodHandle},
 222  * refers directly to an associated {@code CONSTANT_Methodref},
 223  * {@code CONSTANT_InterfaceMethodref}, or {@code CONSTANT_Fieldref}
 224  * constant pool entry.
 225  * (For full details on method handle constants,
 226  * see sections 4.4.8 and 5.4.3.5 of the Java Virtual Machine Specification.)
 227  * <p>
 228  * Method handles produced by lookups or constant loads from methods or
 229  * constructors with the variable arity modifier bit ({@code 0x0080})
 230  * have a corresponding variable arity, as if they were defined with
 231  * the help of {@link #asVarargsCollector asVarargsCollector}
 232  * or {@link #withVarargs withVarargs}.
 233  * <p>
 234  * A method reference may refer either to a static or non-static method.
 235  * In the non-static case, the method handle type includes an explicit
 236  * receiver argument, prepended before any other arguments.
 237  * In the method handle's type, the initial receiver argument is typed
 238  * according to the class under which the method was initially requested.
 239  * (E.g., if a non-static method handle is obtained via {@code ldc},
 240  * the type of the receiver is the class named in the constant pool entry.)
 241  * <p>
 242  * Method handle constants are subject to the same link-time access checks
 243  * their corresponding bytecode instructions, and the {@code ldc} instruction
 244  * will throw corresponding linkage errors if the bytecode behaviors would
 245  * throw such errors.
 246  * <p>




 206  * the untrusted code would be harmless.
 207  *
 208  * <h2>Method handle creation</h2>
 209  * Java code can create a method handle that directly accesses
 210  * any method, constructor, or field that is accessible to that code.
 211  * This is done via a reflective, capability-based API called
 212  * {@link java.lang.invoke.MethodHandles.Lookup MethodHandles.Lookup}.
 213  * For example, a static method handle can be obtained
 214  * from {@link java.lang.invoke.MethodHandles.Lookup#findStatic Lookup.findStatic}.
 215  * There are also conversion methods from Core Reflection API objects,
 216  * such as {@link java.lang.invoke.MethodHandles.Lookup#unreflect Lookup.unreflect}.
 217  * <p>
 218  * Like classes and strings, method handles that correspond to accessible
 219  * fields, methods, and constructors can also be represented directly
 220  * in a class file's constant pool as constants to be loaded by {@code ldc} bytecodes.
 221  * A new type of constant pool entry, {@code CONSTANT_MethodHandle},
 222  * refers directly to an associated {@code CONSTANT_Methodref},
 223  * {@code CONSTANT_InterfaceMethodref}, or {@code CONSTANT_Fieldref}
 224  * constant pool entry.
 225  * (For full details on method handle constants,
 226  * see sections {@jvms 4.4.8} and {@jvms 5.4.3.5} of the Java Virtual Machine Specification.)
 227  * <p>
 228  * Method handles produced by lookups or constant loads from methods or
 229  * constructors with the variable arity modifier bit ({@code 0x0080})
 230  * have a corresponding variable arity, as if they were defined with
 231  * the help of {@link #asVarargsCollector asVarargsCollector}
 232  * or {@link #withVarargs withVarargs}.
 233  * <p>
 234  * A method reference may refer either to a static or non-static method.
 235  * In the non-static case, the method handle type includes an explicit
 236  * receiver argument, prepended before any other arguments.
 237  * In the method handle's type, the initial receiver argument is typed
 238  * according to the class under which the method was initially requested.
 239  * (E.g., if a non-static method handle is obtained via {@code ldc},
 240  * the type of the receiver is the class named in the constant pool entry.)
 241  * <p>
 242  * Method handle constants are subject to the same link-time access checks
 243  * their corresponding bytecode instructions, and the {@code ldc} instruction
 244  * will throw corresponding linkage errors if the bytecode behaviors would
 245  * throw such errors.
 246  * <p>


< prev index next >