# MethodHandles.Lookup

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Constants](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#constants)\|[Methods](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#inhmethods)  

# MethodHandles.Lookup

`
public
static
final

class
MethodHandles.Lookup
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|---------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | java.lang.invoke.MethodHandles.Lookup |

<br />

*** ** * ** ***

A*lookup object* is a factory for creating method handles, when the creation requires access checking. Method handles do not perform access checks when they are called, but rather when they are created. Therefore, method handle access restrictions must be enforced when a method handle is created. The caller class against which those restrictions are enforced is known as the[lookup class](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupClass()).

A lookup class which needs to create method handles will call[MethodHandles.lookup](https://developer.android.com/reference/java/lang/invoke/MethodHandles#lookup())to create a factory for itself. When the`Lookup`factory object is created, the identity of the lookup class is determined, and securely stored in the`Lookup`object. The lookup class (or its delegates) may then use factory methods on the`Lookup`object to create method handles for access-checked members. This includes all methods, constructors, and fields which are allowed to the lookup class, even private ones.

# Lookup Factory Methods

The factory methods on a`Lookup`object correspond to all major use cases for methods, constructors, and fields. Each method handle created by a factory method is the functional equivalent of a particular*bytecode behavior* . (Bytecode behaviors are described in section 5.4.3.5 of the Java Virtual Machine Specification.) Here is a summary of the correspondence between these factory methods and the behavior the resulting method handles:

|                                                                                                            lookup expression                                                                                                            |         member         |            bytecode behavior            |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|-----------------------------------------|
| [lookup.findGetter(C.class,"f",FT.class)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findGetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))                                       | `FT f;`                | `(T) this.f;`                           |
| [lookup.findStaticGetter(C.class,"f",FT.class)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStaticGetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))                           | `static` `FT f;`       | `(T) C.f;`                              |
| [lookup.findSetter(C.class,"f",FT.class)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findSetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))                                       | `FT f;`                | `this.f = x;`                           |
| [lookup.findStaticSetter(C.class,"f",FT.class)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStaticSetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))                           | `static` `FT f;`       | `C.f = arg;`                            |
| [lookup.findVirtual(C.class,"m",MT)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findVirtual(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType))                                  | `T m(A*);`             | `(T) this.m(arg*);`                     |
| [lookup.findStatic(C.class,"m",MT)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStatic(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType))                                    | `static` `T m(A*);`    | `(T) C.m(arg*);`                        |
| [lookup.findSpecial(C.class,"m",MT,this.class)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findSpecial(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Class<?>)) | `T m(A*);`             | `(T) super.m(arg*);`                    |
| [lookup.findConstructor(C.class,MT)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findConstructor(java.lang.Class<?>,%20java.lang.invoke.MethodType))                                                  | `C(A*);`               | `new C(arg*);`                          |
| [lookup.unreflectGetter(aField)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectGetter(java.lang.reflect.Field))                                                                                | (`static`)? `FT f;`    | `(FT) aField.get(thisOrNull);`          |
| [lookup.unreflectSetter(aField)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectSetter(java.lang.reflect.Field))                                                                                | (`static`)? `FT f;`    | `aField.set(thisOrNull, arg);`          |
| [lookup.unreflect(aMethod)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflect(java.lang.reflect.Method))                                                                                          | (`static`)? `T m(A*);` | `(T) aMethod.invoke(thisOrNull, arg*);` |
| [lookup.unreflectConstructor(aConstructor)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectConstructor(java.lang.reflect.Constructor<?>))                                                       | `C(A*);`               | `(C) aConstructor.newInstance(arg*);`   |
| [lookup.unreflect(aMethod)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflect(java.lang.reflect.Method))                                                                                          | (`static`)? `T m(A*);` | `(T) aMethod.invoke(thisOrNull, arg*);` |

Here, the type`C`is the class or interface being searched for a member, documented as a parameter named`refc`in the lookup methods. The method type`MT`is composed from the return type`T`and the sequence of argument types`A*`. The constructor also has a sequence of argument types`A*`and is deemed to return the newly-created object of type`C`. Both`MT`and the field type`FT`are documented as a parameter named`type`. The formal parameter`this`stands for the self-reference of type`C`; if it is present, it is always the leading argument to the method handle invocation. (In the case of some`protected`members,`this`may be restricted in type to the lookup class; see below.) The name`arg`stands for all the other method handle arguments. In the code examples for the Core Reflection API, the name`thisOrNull`stands for a null reference if the accessed method or field is static, and`this`otherwise. The names`aMethod`,`aField`, and`aConstructor`stand for reflective objects corresponding to the given members.

In cases where the given member is of variable arity (i.e., a method or constructor) the returned method handle will also be of[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>)). In all other cases, the returned method handle will be of fixed arity.

*Discussion:*The equivalence between looked-up method handles and underlying class members and bytecode behaviors can break down in a few ways:

- If`C`is not symbolically accessible from the lookup class's loader, the lookup can still succeed, even when there is no equivalent Java expression or bytecoded constant.
- Likewise, if`T`or`MT`is not symbolically accessible from the lookup class's loader, the lookup can still succeed. For example, lookups for`MethodHandle.invokeExact`and`MethodHandle.invoke`will always succeed, regardless of requested type.
- If there is a security manager installed, it can forbid the lookup on various grounds ([see below](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr)). By contrast, the`ldc`instruction on a`CONSTANT_MethodHandle`constant is not subject to security manager checks.
- If the looked-up method has a[very large arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#maxarity), the method handle creation may fail, due to the method handle type having too many parameters.

# Access checking

Access checks are applied in the factory methods of`Lookup`, when a method handle is created. This is a key difference from the Core Reflection API, since[java.lang.reflect.Method.invoke](https://developer.android.com/reference/java/lang/reflect/Method#invoke(java.lang.Object,%20java.lang.Object[]))performs access checking against every caller, on every call.

All access checks start from a`Lookup`object, which compares its recorded lookup class against all requests to create method handles. A single`Lookup`object can be used to create any number of access-checked method handles, all checked against a single lookup class.

A`Lookup`object can be shared with other trusted code, such as a metaobject protocol. A shared`Lookup`object delegates the capability to create method handles on private members of the lookup class. Even if privileged code uses the`Lookup`object, the access checking is confined to the privileges of the original lookup class.

A lookup can fail, because the containing class is not accessible to the lookup class, or because the desired class member is missing, or because the desired class member is not accessible to the lookup class, or because the lookup object is not trusted enough to access the member. In any of these cases, a`ReflectiveOperationException`will be thrown from the attempted lookup. The exact class will be one of the following:

- NoSuchMethodException --- if a method is requested but does not exist
- NoSuchFieldException --- if a field is requested but does not exist
- IllegalAccessException --- if the member exists but an access check fails

In general, the conditions under which a method handle may be looked up for a method`M`are no more restrictive than the conditions under which the lookup class could have compiled, verified, and resolved a call to`M`. Where the JVM would raise exceptions like`NoSuchMethodError`, a method handle lookup will generally raise a corresponding checked exception, such as`NoSuchMethodException`. And the effect of invoking the method handle resulting from the lookup is[exactly equivalent](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#equiv)to executing the compiled, verified, and resolved call to`M`. The same point is true of fields and constructors.

*Discussion:* Access checks only apply to named and reflected methods, constructors, and fields. Other method handle creation methods, such as[MethodHandle.asType](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asType(java.lang.invoke.MethodType)), do not require any access checks, and are used independently of any`Lookup`object.

If the desired member is`protected`, the usual JVM rules apply, including the requirement that the lookup class must be either be in the same package as the desired member, or must inherit that member. (See the Java Virtual Machine Specification, sections 4.9.2, 5.4.3.5, and 6.4.) In addition, if the desired member is a non-static field or method in a different package, the resulting method handle may only be applied to objects of the lookup class or one of its subclasses. This requirement is enforced by narrowing the type of the leading`this`parameter from`C`(which will necessarily be a superclass of the lookup class) to the lookup class itself.

The JVM imposes a similar requirement on`invokespecial`instruction, that the receiver argument must match both the resolved method*and*the current class. Again, this requirement is enforced by narrowing the type of the leading parameter to the resulting method handle. (See the Java Virtual Machine Specification, section 4.10.1.9.)

The JVM represents constructors and static initializer blocks as internal methods with special names (`"<init>"`and`"<clinit>"`). The internal syntax of invocation instructions allows them to refer to such internal methods as if they were normal methods, but the JVM bytecode verifier rejects them. A lookup of such an internal method will produce a`NoSuchMethodException`.

In some cases, access between nested classes is obtained by the Java compiler by creating an wrapper method to access a private method of another class in the same top-level declaration. For example, a nested class`C.D`can access private members within other related classes such as`C`,`C.D.E`, or`C.B`, but the Java compiler may need to generate wrapper methods in those related classes. In such cases, a`Lookup`object on`C.E`would be unable to those private members. A workaround for this limitation is the[Lookup.in](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))method, which can transform a lookup on`C.E`into one on any of those other classes, without special elevation of privilege.

The accesses permitted to a given lookup object may be limited, according to its set of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()), to a subset of members normally accessible to the lookup class. For example, the[publicLookup](https://developer.android.com/reference/java/lang/invoke/MethodHandles#publicLookup())method produces a lookup object which is only allowed to access public members in public classes. The caller sensitive method[lookup](https://developer.android.com/reference/java/lang/invoke/MethodHandles#lookup())produces a lookup object with full capabilities relative to its caller class, to emulate all supported bytecode behaviors. Also, the[Lookup.in](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))method may produce a lookup object with fewer access modes than the original lookup object.

*Discussion of private access:* We say that a lookup has*private access* if its[lookup modes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes())include the possibility of accessing`private`members. As documented in the relevant methods elsewhere, only lookups with private access possess the following capabilities:

- access private fields, methods, and constructors of the lookup class
- create method handles which invoke[caller sensitive](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#callsens)methods, such as`Class.forName`
- create method handles which[emulate invokespecial](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findSpecial(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Class<?>))instructions
- avoid[package access checks](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr)for classes accessible to the lookup class
- create[delegated lookup objects](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))which have private access to other classes within the same package member

Each of these permissions is a consequence of the fact that a lookup object with private access can be securely traced back to an originating class, whose[bytecode behaviors](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#equiv)and Java language access permissions can be reliably determined and emulated by method handles.

# Security manager interactions

Although bytecode instructions can only refer to classes in a related class loader, this API can search for methods in any class, as long as a reference to its`Class`object is available. Such cross-loader references are also possible with the Core Reflection API, and are impossible to bytecode instructions such as`invokestatic`or`getfield`. There is a[security manager API](https://developer.android.com/reference/java/lang/SecurityManager)to allow applications to check such cross-loader references. These checks apply to both the`MethodHandles.Lookup`API and the Core Reflection API (as found on[Class](https://developer.android.com/reference/java/lang/Class)).

If a security manager is present, member lookups are subject to additional checks. From one to three calls are made to the security manager. Any of these calls can refuse access by throwing a[SecurityException](https://developer.android.com/reference/java/lang/SecurityException). Define`smgr`as the security manager,`lookc`as the lookup class of the current lookup object,`refc`as the containing class in which the member is being sought, and`defc`as the class in which the member is actually defined. The value`lookc`is defined as*not present* if the current lookup object does not have[private access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#privacc). The calls are made according to the following rules:

- **Step 1:** If`lookc`is not present, or if its class loader is not the same as or an ancestor of the class loader of`refc`, then[smgr.checkPackageAccess(refcPkg)](https://developer.android.com/reference/java/lang/SecurityManager#checkPackageAccess(java.lang.String))is called, where`refcPkg`is the package of`refc`.
- **Step 2:** If the retrieved member is not public and`lookc`is not present, then[smgr.checkPermission](https://developer.android.com/reference/java/lang/SecurityManager#checkPermission(java.security.Permission))with`RuntimePermission("accessDeclaredMembers")`is called.
- **Step 3:** If the retrieved member is not public, and if`lookc`is not present, and if`defc`and`refc`are different, then[smgr.checkPackageAccess(defcPkg)](https://developer.android.com/reference/java/lang/SecurityManager#checkPackageAccess(java.lang.String))is called, where`defcPkg`is the package of`defc`.

Security checks are performed after other access checks have passed. Therefore, the above rules presuppose a member that is public, or else that is being accessed from a lookup class that has rights to access the member.

# Caller sensitive methods

A small number of Java methods have a special property called caller sensitivity. A*caller-sensitive* method can behave differently depending on the identity of its immediate caller.

If a method handle for a caller-sensitive method is requested, the general rules for[bytecode behaviors](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#equiv)apply, but they take account of the lookup class in a special way. The resulting method handle behaves as if it were called from an instruction contained in the lookup class, so that the caller-sensitive method detects the lookup class. (By contrast, the invoker of the method handle is disregarded.) Thus, in the case of caller-sensitive methods, different lookup classes may give rise to differently behaving method handles.

In cases where the lookup object is[publicLookup()](https://developer.android.com/reference/java/lang/invoke/MethodHandles#publicLookup()), or some other lookup object without[private access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#privacc), the lookup class is disregarded. In such cases, no caller-sensitive method handle can be created, access is forbidden, and the lookup fails with an`IllegalAccessException`.

*Discussion:* For example, the caller-sensitive method[Class.forName(x)](https://developer.android.com/reference/java/lang/Class#forName(java.lang.String))can return varying classes or throw varying exceptions, depending on the class loader of the class that calls it. A public lookup of`Class.forName`will fail, because there is no reasonable way to determine its bytecode behavior.

If an application caches method handles for broad sharing, it should use`publicLookup()`to create them. If there is a lookup of`Class.forName`, it will fail, and the application must take appropriate action in that case. It may be that a later lookup, perhaps during the invocation of a bootstrap method, can incorporate the specific identity of the caller, making the method accessible.

The function`MethodHandles.lookup`is caller sensitive so that there can be a secure foundation for lookups. Nearly all other methods in the JSR 292 API rely on lookup objects to check access requests.

## Summary

|                                                                                                                                                      ### Constants                                                                                                                                                       ||
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [PACKAGE](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PACKAGE) A single-bit mask representing`package`access (default access), which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()). |
| `int` | [PRIVATE](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PRIVATE) A single-bit mask representing`private`access, which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()).                  |
| `int` | [PROTECTED](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PROTECTED) A single-bit mask representing`protected`access, which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()).            |
| `int` | [PUBLIC](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PUBLIC) A single-bit mask representing`public`access, which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()).                     |

|                                                                                                                                                                                                                                                                                                                                                   ### Public methods                                                                                                                                                                                                                                                                                                                                                    ||
|----------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[bind](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#bind(java.lang.Object,%20java.lang.String,%20java.lang.invoke.MethodType))`(`[Object](https://developer.android.com/reference/java/lang/Object)` receiver, `[String](https://developer.android.com/reference/java/lang/String)` name, `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` type) ` Produces an early-bound method handle for a non-static method.                                                                                                                      |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findConstructor](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findConstructor(java.lang.Class<?>,%20java.lang.invoke.MethodType))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` type) ` Produces a method handle which creates an object and initializes it, using the constructor of the specified type.                                                                                                                                             |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findGetter](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findGetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> type) ` Produces a method handle giving read access to a non-static field.                                                                                                                              |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findSetter](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findSetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> type) ` Produces a method handle giving write access to a non-static field.                                                                                                                             |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findSpecial](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findSpecial(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` type, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> specialCaller) ` Produces an early-bound method handle for a virtual method. |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findStatic](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStatic(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` type) ` Produces a method handle for a static method.                                                                                                                            |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findStaticGetter](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStaticGetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> type) ` Produces a method handle giving read access to a static field.                                                                                                                      |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findStaticSetter](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStaticSetter(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> type) ` Produces a method handle giving write access to a static field.                                                                                                                     |
| ` `[VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle)                       | ` `[findStaticVarHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findStaticVarHandle(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> decl, `[String](https://developer.android.com/reference/java/lang/String)` name, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> type) ` Produces a VarHandle giving access to a static field`name`of type`type`declared in a class of type`decl`.                                                                     |
| ` `[VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle)                       | ` `[findVarHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findVarHandle(java.lang.Class<?>,%20java.lang.String,%20java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> recv, `[String](https://developer.android.com/reference/java/lang/String)` name, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> type) ` Produces a VarHandle giving access to a non-static field`name`of type`type`declared in a class of type`recv`.                                                                             |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[findVirtual](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findVirtual(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> refc, `[String](https://developer.android.com/reference/java/lang/String)` name, `[MethodType](https://developer.android.com/reference/java/lang/invoke/MethodType)` type) ` Produces a method handle for a virtual method.                                                                                                                         |
| ` `[MethodHandles.Lookup](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup) | ` `[in](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> requestedLookupClass) ` Creates a lookup on the specified new lookup class.                                                                                                                                                                                                                                                                                                                                              |
| ` `[Class](https://developer.android.com/reference/java/lang/Class)`<?>`                                 | ` `[lookupClass](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupClass())`() ` Tells which class is performing the lookup.                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` int`                                                                                                   | ` `[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes())`() ` Tells which access-protection classes of members this lookup object can produce.                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` `[MethodHandleInfo](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo)         | ` `[revealDirect](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#revealDirect(java.lang.invoke.MethodHandle))`(`[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)` target) ` Cracks a[direct method handle](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo#directmh)created by this lookup object or a similar one.                                                                                                                                                                                             |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                    | ` `[toString](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#toString())`() ` Displays the name of the class from which lookups are to be made.                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[unreflect](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflect(java.lang.reflect.Method))`(`[Method](https://developer.android.com/reference/java/lang/reflect/Method)` m) ` Makes a[direct method handle](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo#directmh)to*m*, if the lookup class has permission.                                                                                                                                                                                                                              |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[unreflectConstructor](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectConstructor(java.lang.reflect.Constructor<?>))`(`[Constructor](https://developer.android.com/reference/java/lang/reflect/Constructor)`<?> c) ` Produces a method handle for a reflected constructor.                                                                                                                                                                                                                                                                                         |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[unreflectGetter](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectGetter(java.lang.reflect.Field))`(`[Field](https://developer.android.com/reference/java/lang/reflect/Field)` f) ` Produces a method handle giving read access to a reflected field.                                                                                                                                                                                                                                                                                                               |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[unreflectSetter](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectSetter(java.lang.reflect.Field))`(`[Field](https://developer.android.com/reference/java/lang/reflect/Field)` f) ` Produces a method handle giving write access to a reflected field.                                                                                                                                                                                                                                                                                                              |
| ` `[MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle)                 | ` `[unreflectSpecial](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectSpecial(java.lang.reflect.Method,%20java.lang.Class<?>))`(`[Method](https://developer.android.com/reference/java/lang/reflect/Method)` m, `[Class](https://developer.android.com/reference/java/lang/Class)`<?> specialCaller) ` Produces a method handle for a reflected method.                                                                                                                                                                                                                |
| ` `[VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle)                       | ` `[unreflectVarHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#unreflectVarHandle(java.lang.reflect.Field))`(`[Field](https://developer.android.com/reference/java/lang/reflect/Field)` f) ` Produces a VarHandle giving access to a reflected field`f`of type`T`declared in a class of type`R`.                                                                                                                                                                                                                                                                       |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### PACKAGE

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int PACKAGE
```

A single-bit mask representing`package`access (default access), which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()). The value is`0x08`, which does not correspond meaningfully to any particular[modifier bit](https://developer.android.com/reference/java/lang/reflect/Modifier).

<br />

Constant Value: 8 (0x00000008)  

### PRIVATE

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int PRIVATE
```

A single-bit mask representing`private`access, which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()). The value,`0x02`, happens to be the same as the value of the`private`[modifier bit](https://developer.android.com/reference/java/lang/reflect/Modifier#PRIVATE).

<br />

Constant Value: 2 (0x00000002)  

### PROTECTED

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int PROTECTED
```

A single-bit mask representing`protected`access, which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()). The value,`0x04`, happens to be the same as the value of the`protected`[modifier bit](https://developer.android.com/reference/java/lang/reflect/Modifier#PROTECTED).

<br />

Constant Value: 4 (0x00000004)  

### PUBLIC

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int PUBLIC
```

A single-bit mask representing`public`access, which may contribute to the result of[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()). The value,`0x01`, happens to be the same as the value of the`public`[modifier bit](https://developer.android.com/reference/java/lang/reflect/Modifier#PUBLIC).

<br />

Constant Value: 1 (0x00000001)

## Public methods

### bind

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle bind (Object receiver, 
                String name, 
                MethodType type)
```

Produces an early-bound method handle for a non-static method. The receiver must have a supertype`defc`in which a method of the given name and type is accessible to the lookup class. The method and all its argument types must be accessible to the lookup object. The type of the method handle will be that of the method, without any insertion of an additional receiver parameter. The given receiver will be bound into the method handle, so that every call to the method handle will invoke the requested method on the given receiver.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the method's variable arity modifier bit (`0x0080`) is set*and*the trailing array argument is not the only argument. (If the trailing array argument is the only argument, the given receiver value will be bound to it.)

This is equivalent to the following code:
>
>     import static java.lang.invoke.MethodHandles.*;
>      import static java.lang.invoke.MethodType.*;
>      ...
>      MethodHandle mh0 = lookup().findVirtual(defc, name, type);
>      MethodHandle mh1 = mh0.bindTo(receiver);
>      MethodType mt1 = mh1.type();
>      if (mh0.isVarargsCollector())
>      mh1 = mh1.asVarargsCollector(mt1.parameterType(mt1.parameterCount()-1));
>      return mh1;
>      
where`defc`is either`receiver.getClass()`or a super type of that class, in which the requested method is accessible to the lookup class. (Note that`bindTo`does not preserve variable arity.)

<br />

<br />

|                                         Parameters                                          ||
|------------|---------------------------------------------------------------------------------|
| `receiver` | `Object`: the object from which the method is accessed <br />                   |
| `name`     | `String`: the name of the method <br />                                         |
| `type`     | `MethodType`: the type of the method, with the receiver argument omitted <br /> |

|                                                         Returns                                                         ||
|---------------------------------------------------------------------------------------|----------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the desired method handle <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchMethodException](https://developer.android.com/reference/java/lang/NoSuchMethodException)   | if the method does not exist                                                                                                                  |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails or if the method's variable arity modifier bit is set and`asVarargsCollector`fails                                   |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

**See also:**

- [MethodHandle.bindTo(Object)](https://developer.android.com/reference/java/lang/invoke/MethodHandle#bindTo(java.lang.Object))
- [findVirtual(Class, String, MethodType)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findVirtual(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType))  

### findConstructor

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findConstructor (Class<?> refc, 
                MethodType type)
```

Produces a method handle which creates an object and initializes it, using the constructor of the specified type. The parameter types of the method handle will be those of the constructor, while the return type will be a reference to the constructor's class. The constructor and all its argument types must be accessible to the lookup object.

The requested type must have a return type of`void`. (This is consistent with the JVM's treatment of constructor type descriptors.)

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the constructor's variable arity modifier bit (`0x0080`) is set.

If the returned method handle is invoked, the constructor's class will be initialized, if it has not already been initialized.

**Example:**
>
>     import static java.lang.invoke.MethodHandles.*;
>      import static java.lang.invoke.MethodType.*;
>      ...
>      MethodHandle MH_newArrayList = publicLookup().findConstructor(
>      ArrayList.class, methodType(void.class, Collection.class));
>      Collection orig = Arrays.asList("x", "y");
>      Collection copy = (ArrayList) MH_newArrayList.invokeExact(orig);
>      assert(orig != copy);
>      assertEquals(orig, copy);
>      // a variable-arity constructor:
>      MethodHandle MH_newProcessBuilder = publicLookup().findConstructor(
>      ProcessBuilder.class, methodType(void.class, String[].class));
>      ProcessBuilder pb = (ProcessBuilder)
>      MH_newProcessBuilder.invoke("x", "y", "z");
>      assertEquals("[x, y, z]", pb.command().toString());
>      
<br />

<br />

|                                                   Parameters                                                    ||
|--------|---------------------------------------------------------------------------------------------------------|
| `refc` | `Class`: the class or interface from which the method is accessed <br />                                |
| `type` | `MethodType`: the type of the method, with the receiver argument omitted, and a void return type <br /> |

|                                                         Returns                                                         ||
|---------------------------------------------------------------------------------------|----------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the desired method handle <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchMethodException](https://developer.android.com/reference/java/lang/NoSuchMethodException)   | if the constructor does not exist                                                                                                             |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails or if the method's variable arity modifier bit is set and`asVarargsCollector`fails                                   |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findGetter

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findGetter (Class<?> refc, 
                String name, 
                Class<?> type)
```

Produces a method handle giving read access to a non-static field. The type of the method handle will have a return type of the field's value type. The method handle's single argument will be the instance containing the field. Access checking is performed immediately on behalf of the lookup class.

<br />

|                                    Parameters                                    ||
|--------|--------------------------------------------------------------------------|
| `refc` | `Class`: the class or interface from which the method is accessed <br /> |
| `name` | `String`: the field's name <br />                                        |
| `type` | `Class`: the field's type <br />                                         |

|                                                                      Returns                                                                       ||
|---------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can load values from the field <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchFieldException](https://developer.android.com/reference/java/lang/NoSuchFieldException)     | if the field does not exist                                                                                                                   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the field is`static`                                                                                          |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findSetter

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findSetter (Class<?> refc, 
                String name, 
                Class<?> type)
```

Produces a method handle giving write access to a non-static field. The type of the method handle will have a void return type. The method handle will take two arguments, the instance containing the field, and the value to be stored. The second argument will be of the field's value type. Access checking is performed immediately on behalf of the lookup class.

<br />

|                                    Parameters                                    ||
|--------|--------------------------------------------------------------------------|
| `refc` | `Class`: the class or interface from which the method is accessed <br /> |
| `name` | `String`: the field's name <br />                                        |
| `type` | `Class`: the field's type <br />                                         |

|                                                                       Returns                                                                       ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can store values into the field <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchFieldException](https://developer.android.com/reference/java/lang/NoSuchFieldException)     | if the field does not exist                                                                                                                   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the field is`static`                                                                                          |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findSpecial

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findSpecial (Class<?> refc, 
                String name, 
                MethodType type, 
                Class<?> specialCaller)
```

Produces an early-bound method handle for a virtual method. It will bypass checks for overriding methods on the receiver,[as if called](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#equiv)from an`invokespecial`instruction from within the explicitly specified`specialCaller`. The type of the method handle will be that of the method, with a suitably restricted receiver type prepended. (The receiver type will be`specialCaller`or a subtype.) The method and all its argument types must be accessible to the lookup object.

Before method resolution, if the explicitly specified caller class is not identical with the lookup class, or if this lookup object does not have[private access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#privacc)privileges, the access fails.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the method's variable arity modifier bit (`0x0080`) is set.

*(Note: JVM internal methods named`"<init>"`are not visible to this API, even though the`invokespecial`instruction can refer to them in special circumstances. Use[findConstructor](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findConstructor(java.lang.Class<?>,%20java.lang.invoke.MethodType))to access instance initialization methods in a safe manner.)*

**Example:**
>
>     import static java.lang.invoke.MethodHandles.*;
>      import static java.lang.invoke.MethodType.*;
>      ...
>      static class Listie extends ArrayList {
>      public String toString() { return "[wee Listie]"; }
>      static Lookup lookup() { return MethodHandles.lookup(); }
>      }
>      ...
>      // no access to constructor via invokeSpecial:
>      MethodHandle MH_newListie = Listie.lookup()
>      .findConstructor(Listie.class, methodType(void.class));
>      Listie l = (Listie) MH_newListie.invokeExact();
>      try { assertEquals("impossible", Listie.lookup().findSpecial(
>            Listie.class, "<init>", methodType(void.class), Listie.class));
>      } catch (NoSuchMethodException ex) { } // OK
>      // access to super and self methods via invokeSpecial:
>      MethodHandle MH_super = Listie.lookup().findSpecial(
>      ArrayList.class, "toString" , methodType(String.class), Listie.class);
>      MethodHandle MH_this = Listie.lookup().findSpecial(
>      Listie.class, "toString" , methodType(String.class), Listie.class);
>      MethodHandle MH_duper = Listie.lookup().findSpecial(
>      Object.class, "toString" , methodType(String.class), Listie.class);
>      assertEquals("[]", (String) MH_super.invokeExact(l));
>      assertEquals(""+l, (String) MH_this.invokeExact(l));
>      assertEquals("[]", (String) MH_duper.invokeExact(l)); // ArrayList method
>      try { assertEquals("inaccessible", Listie.lookup().findSpecial(
>            String.class, "toString", methodType(String.class), Listie.class));
>      } catch (IllegalAccessException ex) { } // OK
>      Listie subl = new Listie() { public String toString() { return "[subclass]"; } };
>      assertEquals(""+l, (String) MH_this.invokeExact(subl)); // Listie method
>      
<br />

<br />

|                                            Parameters                                            ||
|-----------------|---------------------------------------------------------------------------------|
| `refc`          | `Class`: the class or interface from which the method is accessed <br />        |
| `name`          | `String`: the name of the method (which must not be "\<init\>") <br />          |
| `type`          | `MethodType`: the type of the method, with the receiver argument omitted <br /> |
| `specialCaller` | `Class`: the proposed calling class to perform the`invokespecial` <br />        |

|                                                         Returns                                                         ||
|---------------------------------------------------------------------------------------|----------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the desired method handle <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchMethodException](https://developer.android.com/reference/java/lang/NoSuchMethodException)   | if the method does not exist                                                                                                                  |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails or if the method's variable arity modifier bit is set and`asVarargsCollector`fails                                   |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findStatic

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findStatic (Class<?> refc, 
                String name, 
                MethodType type)
```

Produces a method handle for a static method. The type of the method handle will be that of the method. (Since static methods do not take receivers, there is no additional receiver argument inserted into the method handle type, as there would be with[findVirtual](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findVirtual(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType))or[findSpecial](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#findSpecial(java.lang.Class<?>,%20java.lang.String,%20java.lang.invoke.MethodType,%20java.lang.Class<?>)).) The method and all its argument types must be accessible to the lookup object.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the method's variable arity modifier bit (`0x0080`) is set.

If the returned method handle is invoked, the method's class will be initialized, if it has not already been initialized.

**Example:**
>
>     import static java.lang.invoke.MethodHandles.*;
>      import static java.lang.invoke.MethodType.*;
>      ...
>      MethodHandle MH_asList = publicLookup().findStatic(Arrays.class,
>      "asList", methodType(List.class, Object[].class));
>      assertEquals("[x, y]", MH_asList.invoke("x", "y").toString());
>      
<br />

<br />

|                             Parameters                              ||
|--------|-------------------------------------------------------------|
| `refc` | `Class`: the class from which the method is accessed <br /> |
| `name` | `String`: the name of the method <br />                     |
| `type` | `MethodType`: the type of the method <br />                 |

|                                                         Returns                                                         ||
|---------------------------------------------------------------------------------------|----------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the desired method handle <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchMethodException](https://developer.android.com/reference/java/lang/NoSuchMethodException)   | if the method does not exist                                                                                                                  |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the method is not`static`, or if the method's variable arity modifier bit is set and`asVarargsCollector`fails |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findStaticGetter

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findStaticGetter (Class<?> refc, 
                String name, 
                Class<?> type)
```

Produces a method handle giving read access to a static field. The type of the method handle will have a return type of the field's value type. The method handle will take no arguments. Access checking is performed immediately on behalf of the lookup class.

If the returned method handle is invoked, the field's class will be initialized, if it has not already been initialized.

<br />

|                                    Parameters                                    ||
|--------|--------------------------------------------------------------------------|
| `refc` | `Class`: the class or interface from which the method is accessed <br /> |
| `name` | `String`: the field's name <br />                                        |
| `type` | `Class`: the field's type <br />                                         |

|                                                                      Returns                                                                       ||
|---------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can load values from the field <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchFieldException](https://developer.android.com/reference/java/lang/NoSuchFieldException)     | if the field does not exist                                                                                                                   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the field is not`static`                                                                                      |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findStaticSetter

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findStaticSetter (Class<?> refc, 
                String name, 
                Class<?> type)
```

Produces a method handle giving write access to a static field. The type of the method handle will have a void return type. The method handle will take a single argument, of the field's value type, the value to be stored. Access checking is performed immediately on behalf of the lookup class.

If the returned method handle is invoked, the field's class will be initialized, if it has not already been initialized.

<br />

|                                    Parameters                                    ||
|--------|--------------------------------------------------------------------------|
| `refc` | `Class`: the class or interface from which the method is accessed <br /> |
| `name` | `String`: the field's name <br />                                        |
| `type` | `Class`: the field's type <br />                                         |

|                                                                       Returns                                                                       ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can store values into the field <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchFieldException](https://developer.android.com/reference/java/lang/NoSuchFieldException)     | if the field does not exist                                                                                                                   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the field is not`static`                                                                                      |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findStaticVarHandle

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VarHandle findStaticVarHandle (Class<?> decl, 
                String name, 
                Class<?> type)
```

Produces a VarHandle giving access to a static field`name`of type`type`declared in a class of type`decl`. The VarHandle's variable type is`type`and it has no coordinate types.

Access checking is performed immediately on behalf of the lookup class.

If the returned VarHandle is operated on, the declaring class will be initialized, if it has not already been initialized.

Certain access modes of the returned VarHandle are unsupported under the following conditions:

- if the field is declared`final`, then the write, atomic update, numeric atomic update, and bitwise atomic update access modes are unsupported.
- if the field type is anything other than`byte`,`short`,`char`,`int`,`long`,`float`, or`double`, then numeric atomic update access modes are unsupported.
- if the field type is anything other than`boolean`,`byte`,`short`,`char`,`int`or`long`then bitwise atomic update access modes are unsupported.

If the field is declared`volatile`then the returned VarHandle will override access to the field (effectively ignore the`volatile`declaration) in accordance to its specified access modes.

If the field type is`float`or`double`then numeric and atomic update access modes compare values using their bitwise representation (see[Float.floatToRawIntBits](https://developer.android.com/reference/java/lang/Float#floatToRawIntBits(float))and[Double.doubleToRawLongBits](https://developer.android.com/reference/java/lang/Double#doubleToRawLongBits(double)), respectively).

<br />

##### API Note:

- Bitwise comparison of`float`values or`double`values, as performed by the numeric and atomic update access modes, differ from the primitive`==`operator and the[Float.equals](https://developer.android.com/reference/java/lang/Float#equals(java.lang.Object))and[Double.equals](https://developer.android.com/reference/java/lang/Double#equals(java.lang.Object))methods, specifically with respect to comparing NaN values or comparing`-0.0`with`+0.0`. Care should be taken when performing a compare and set or a compare and exchange operation with such values since the operation may unexpectedly fail. There are many possible NaN values that are considered to be`NaN`in Java, although no IEEE 754 floating-point operation provided by Java can distinguish between them. Operation failure can occur if the expected or witness value is a NaN value and it is transformed (perhaps in a platform specific manner) into another NaN value, and thus has a different bitwise representation (see[Float.intBitsToFloat](https://developer.android.com/reference/java/lang/Float#intBitsToFloat(int))or[Double.longBitsToDouble](https://developer.android.com/reference/java/lang/Double#longBitsToDouble(long))for more details). The values`-0.0`and`+0.0`have different bitwise representations but are considered equal when using the primitive`==`operator. Operation failure can occur if, for example, a numeric algorithm computes an expected value to be say`-0.0`and previously computed the witness value to be say`+0.0`.

|                            Parameters                            ||
|--------|----------------------------------------------------------|
| `decl` | `Class`: the class that declares the static field <br /> |
| `name` | `String`: the field's name <br />                        |
| `type` | `Class`: the field's type, of type`T` <br />             |

|                                                               Returns                                                               ||
|---------------------------------------------------------------------------------|----------------------------------------------------|
| [VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle) | a VarHandle giving access to a static field <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchFieldException](https://developer.android.com/reference/java/lang/NoSuchFieldException)     | if the field does not exist                                                                                                                   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the field is not`static`                                                                                      |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findVarHandle

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VarHandle findVarHandle (Class<?> recv, 
                String name, 
                Class<?> type)
```

Produces a VarHandle giving access to a non-static field`name`of type`type`declared in a class of type`recv`. The VarHandle's variable type is`type`and it has one coordinate type,`recv`.

Access checking is performed immediately on behalf of the lookup class.

Certain access modes of the returned VarHandle are unsupported under the following conditions:

- if the field is declared`final`, then the write, atomic update, numeric atomic update, and bitwise atomic update access modes are unsupported.
- if the field type is anything other than`byte`,`short`,`char`,`int`,`long`,`float`, or`double`then numeric atomic update access modes are unsupported.
- if the field type is anything other than`boolean`,`byte`,`short`,`char`,`int`or`long`then bitwise atomic update access modes are unsupported.

If the field is declared`volatile`then the returned VarHandle will override access to the field (effectively ignore the`volatile`declaration) in accordance to its specified access modes.

If the field type is`float`or`double`then numeric and atomic update access modes compare values using their bitwise representation (see[Float.floatToRawIntBits](https://developer.android.com/reference/java/lang/Float#floatToRawIntBits(float))and[Double.doubleToRawLongBits](https://developer.android.com/reference/java/lang/Double#doubleToRawLongBits(double)), respectively).

<br />

##### API Note:

- Bitwise comparison of`float`values or`double`values, as performed by the numeric and atomic update access modes, differ from the primitive`==`operator and the[Float.equals](https://developer.android.com/reference/java/lang/Float#equals(java.lang.Object))and[Double.equals](https://developer.android.com/reference/java/lang/Double#equals(java.lang.Object))methods, specifically with respect to comparing NaN values or comparing`-0.0`with`+0.0`. Care should be taken when performing a compare and set or a compare and exchange operation with such values since the operation may unexpectedly fail. There are many possible NaN values that are considered to be`NaN`in Java, although no IEEE 754 floating-point operation provided by Java can distinguish between them. Operation failure can occur if the expected or witness value is a NaN value and it is transformed (perhaps in a platform specific manner) into another NaN value, and thus has a different bitwise representation (see[Float.intBitsToFloat](https://developer.android.com/reference/java/lang/Float#intBitsToFloat(int))or[Double.longBitsToDouble](https://developer.android.com/reference/java/lang/Double#longBitsToDouble(long))for more details). The values`-0.0`and`+0.0`have different bitwise representations but are considered equal when using the primitive`==`operator. Operation failure can occur if, for example, a numeric algorithm computes an expected value to be say`-0.0`and previously computed the witness value to be say`+0.0`.

|                                         Parameters                                         ||
|--------|------------------------------------------------------------------------------------|
| `recv` | `Class`: the receiver class, of type`R`, that declares the non-static field <br /> |
| `name` | `String`: the field's name <br />                                                  |
| `type` | `Class`: the field's type, of type`T` <br />                                       |

|                                                                 Returns                                                                 ||
|---------------------------------------------------------------------------------|--------------------------------------------------------|
| [VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle) | a VarHandle giving access to non-static fields. <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchFieldException](https://developer.android.com/reference/java/lang/NoSuchFieldException)     | if the field does not exist                                                                                                                   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the field is`static`                                                                                          |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### findVirtual

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle findVirtual (Class<?> refc, 
                String name, 
                MethodType type)
```

Produces a method handle for a virtual method. The type of the method handle will be that of the method, with the receiver type (usually`refc`) prepended. The method and all its argument types must be accessible to the lookup object.

When called, the handle will treat the first argument as a receiver and dispatch on the receiver's type to determine which method implementation to enter. (The dispatching action is identical with that performed by an`invokevirtual`or`invokeinterface`instruction.)

The first argument will be of type`refc`if the lookup class has full privileges to access the member. Otherwise the member must be`protected`and the first argument will be restricted in type to the lookup class.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the method's variable arity modifier bit (`0x0080`) is set.

Because of the general[equivalence](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#equiv)between`invokevirtual`instructions and method handles produced by`findVirtual`, if the class is`MethodHandle`and the name string is`invokeExact`or`invoke`, the resulting method handle is equivalent to one produced by[MethodHandles.exactInvoker](https://developer.android.com/reference/java/lang/invoke/MethodHandles#exactInvoker(java.lang.invoke.MethodType))or[MethodHandles.invoker](https://developer.android.com/reference/java/lang/invoke/MethodHandles#invoker(java.lang.invoke.MethodType))with the same`type`argument.**Example:**
>
>     import static java.lang.invoke.MethodHandles.*;
>      import static java.lang.invoke.MethodType.*;
>      ...
>      MethodHandle MH_concat = publicLookup().findVirtual(String.class,
>      "concat", methodType(String.class, String.class));
>      MethodHandle MH_hashCode = publicLookup().findVirtual(Object.class,
>      "hashCode", methodType(int.class));
>      MethodHandle MH_hashCode_String = publicLookup().findVirtual(String.class,
>      "hashCode", methodType(int.class));
>      assertEquals("xy", (String) MH_concat.invokeExact("x", "y"));
>      assertEquals("xy".hashCode(), (int) MH_hashCode.invokeExact((Object)"xy"));
>      assertEquals("xy".hashCode(), (int) MH_hashCode_String.invokeExact("xy"));
>      // interface method:
>      MethodHandle MH_subSequence = publicLookup().findVirtual(CharSequence.class,
>      "subSequence", methodType(CharSequence.class, int.class, int.class));
>      assertEquals("def", MH_subSequence.invoke("abcdefghi", 3, 6).toString());
>      // constructor "internal method" must be accessed differently:
>      MethodType MT_newString = methodType(void.class); //()V for new String()
>      try { assertEquals("impossible", lookup()
>            .findVirtual(String.class, "<init>", MT_newString));
>      } catch (NoSuchMethodException ex) { } // OK
>      MethodHandle MH_newString = publicLookup()
>      .findConstructor(String.class, MT_newString);
>      assertEquals("", (String) MH_newString.invokeExact());
>      
<br />

<br />

|                                       Parameters                                        ||
|--------|---------------------------------------------------------------------------------|
| `refc` | `Class`: the class or interface from which the method is accessed <br />        |
| `name` | `String`: the name of the method <br />                                         |
| `type` | `MethodType`: the type of the method, with the receiver argument omitted <br /> |

|                                                         Returns                                                         ||
|---------------------------------------------------------------------------------------|----------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | the desired method handle <br /> |

|                                                                                                                      Throws                                                                                                                       ||
|----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [NoSuchMethodException](https://developer.android.com/reference/java/lang/NoSuchMethodException)   | if the method does not exist                                                                                                                  |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails, or if the method is`static`or if the method's variable arity modifier bit is set and`asVarargsCollector`fails       |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)           | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                                                       |

### in

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandles.Lookup in (Class<?> requestedLookupClass)
```

Creates a lookup on the specified new lookup class. The resulting object will report the specified class as its own[lookupClass](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupClass()).

However, the resulting`Lookup`object is guaranteed to have no more access capabilities than the original. In particular, access capabilities can be lost as follows:

- If the new lookup class differs from the old one, protected members will not be accessible by virtue of inheritance. (Protected members may continue to be accessible because of package sharing.)
- If the new lookup class is in a different package than the old one, protected and default (package) members will not be accessible.
- If the new lookup class is not within the same package member as the old one, private members will not be accessible.
- If the new lookup class is not accessible to the old lookup class, then no members, not even public members, will be accessible. (In all other cases, public members will continue to be accessible.)

<br />

<br />

|                                         Parameters                                         ||
|------------------------|--------------------------------------------------------------------|
| `requestedLookupClass` | `Class`: the desired lookup class for the new lookup object <br /> |

|                                                                               Returns                                                                                ||
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| [MethodHandles.Lookup](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup) | a lookup object which reports the desired lookup class <br /> |

|                                                         Throws                                                          ||
|------------------------------------------------------------------------------------------------|-------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if the argument is null |

### lookupClass

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Class<?> lookupClass ()
```

Tells which class is performing the lookup. It is this class against which checks are performed for visibility and access permissions.

The class implies a maximum level of access permission, but the permissions may be additionally limited by the bitmask[lookupModes](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#lookupModes()), which controls whether non-public members can be accessed.

<br />

|                                                                       Returns                                                                       ||
|-----------------------------------------------------------------------|------------------------------------------------------------------------------|
| [Class](https://developer.android.com/reference/java/lang/Class)`<?>` | the lookup class, on behalf of which this lookup object finds members <br /> |

### lookupModes

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int lookupModes ()
```

Tells which access-protection classes of members this lookup object can produce. The result is a bit-mask of the bits[PUBLIC (0x01)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PUBLIC),[PRIVATE (0x02)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PRIVATE),[PROTECTED (0x04)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PROTECTED), and[PACKAGE (0x08)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#PACKAGE).

A freshly-created lookup object on the[caller's class](https://developer.android.com/reference/java/lang/invoke/MethodHandles#lookup())has all possible bits set, since the caller class can access all its own members. A lookup object on a new lookup class[created from a previous lookup object](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))may have some mode bits set to zero. The purpose of this is to restrict access via the new lookup object, so that it can access only names which can be reached by the original lookup object, and also by the new lookup class.

<br />

|                                             Returns                                             ||
|-------|------------------------------------------------------------------------------------------|
| `int` | the lookup modes, which limit the kinds of access performed by this lookup object <br /> |

### revealDirect

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandleInfo revealDirect (MethodHandle target)
```

Cracks a[direct method handle](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo#directmh)created by this lookup object or a similar one. Security and access checks are performed to ensure that this lookup object is capable of reproducing the target method handle. This means that the cracking may fail if target is a direct method handle but was created by an unrelated lookup object. This can happen if the method handle is[caller sensitive](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#callsens)and was created by a lookup object for a different class.

<br />

|                                             Parameters                                              ||
|----------|-------------------------------------------------------------------------------------------|
| `target` | `MethodHandle`: a direct method handle to crack into symbolic reference components <br /> |

|                                                                                                Returns                                                                                                 ||
|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [MethodHandleInfo](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo) | a symbolic reference which can be used to reconstruct this method handle from this lookup object <br /> |

|                                                                                                                        Throws                                                                                                                         ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)               | if a security manager is present and it[refuses access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#secmgr) |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the target is not a direct method handle or if access checking fails                                                                       |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)         | if the target is`null`                                                                                                                        |

**See also:**

- [MethodHandleInfo](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo)  

### toString

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String toString ()
```

Displays the name of the class from which lookups are to be made. (The name is the one reported by[Class.getName](https://developer.android.com/reference/java/lang/Class#getName()).) If there are restrictions on the access permitted to this lookup, this is indicated by adding a suffix to the class name, consisting of a slash and a keyword. The keyword represents the strongest allowed access, and is chosen as follows:

- If no access is allowed, the suffix is "/noaccess".
- If only public access is allowed, the suffix is "/public".
- If only public and package access are allowed, the suffix is "/package".
- If only public, package, and private access are allowed, the suffix is "/private".

If none of the above cases apply, it is the case that full access (public, package, private, and protected) is allowed. In this case, no suffix is added. This is true only of an object obtained originally from[MethodHandles.lookup](https://developer.android.com/reference/java/lang/invoke/MethodHandles#lookup()). Objects created by[Lookup.in](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))always have restricted access, and will display a suffix.

(It may seem strange that protected access should be stronger than private access. Viewed independently from package access, protected access is the first to be lost, because it requires a direct subclass relationship between caller and callee.)

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |

**See also:**

- [in(Class)](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#in(java.lang.Class<?>))  

### unreflect

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle unreflect (Method m)
```

Makes a[direct method handle](https://developer.android.com/reference/java/lang/invoke/MethodHandleInfo#directmh)to*m* , if the lookup class has permission. If*m* is non-static, the receiver argument is treated as an initial argument. If*m* is virtual, overriding is respected on every call. Unlike the Core Reflection API, exceptions are*not* wrapped. The type of the method handle will be that of the method, with the receiver type prepended (but only if it is non-static). If the method's`accessible`flag is not set, access checking is performed immediately on behalf of the lookup class. If*m*is not public, do not share the resulting handle with untrusted parties.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the method's variable arity modifier bit (`0x0080`) is set.

If*m*is static, and if the returned method handle is invoked, the method's class will be initialized, if it has not already been initialized.

<br />

|                 Parameters                 ||
|-----|---------------------------------------|
| `m` | `Method`: the reflected method <br /> |

|                                                                       Returns                                                                       ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can invoke the reflected method <br /> |

|                                                                                                     Throws                                                                                                      ||
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails or if the method's variable arity modifier bit is set and`asVarargsCollector`fails |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if the argument is null                                                                                     |

### unreflectConstructor

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle unreflectConstructor (Constructor<?> c)
```

Produces a method handle for a reflected constructor. The type of the method handle will be that of the constructor, with the return type changed to the declaring class. The method handle will perform a`newInstance`operation, creating a new instance of the constructor's class on the arguments passed to the method handle.

If the constructor's`accessible`flag is not set, access checking is performed immediately on behalf of the lookup class.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the constructor's variable arity modifier bit (`0x0080`) is set.

If the returned method handle is invoked, the constructor's class will be initialized, if it has not already been initialized.

<br />

|                      Parameters                      ||
|-----|-------------------------------------------------|
| `c` | `Constructor`: the reflected constructor <br /> |

|                                                                         Returns                                                                          ||
|---------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can invoke the reflected constructor <br /> |

|                                                                                                     Throws                                                                                                      ||
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails or if the method's variable arity modifier bit is set and`asVarargsCollector`fails |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if the argument is null                                                                                     |

### unreflectGetter

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle unreflectGetter (Field f)
```

Produces a method handle giving read access to a reflected field. The type of the method handle will have a return type of the field's value type. If the field is static, the method handle will take no arguments. Otherwise, its single argument will be the instance containing the field. If the field's`accessible`flag is not set, access checking is performed immediately on behalf of the lookup class.

If the field is static, and if the returned method handle is invoked, the field's class will be initialized, if it has not already been initialized.

<br />

|                Parameters                ||
|-----|-------------------------------------|
| `f` | `Field`: the reflected field <br /> |

|                                                                           Returns                                                                            ||
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can load values from the reflected field <br /> |

|                                                            Throws                                                            ||
|----------------------------------------------------------------------------------------------------|--------------------------|
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if the argument is null  |

### unreflectSetter

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle unreflectSetter (Field f)
```

Produces a method handle giving write access to a reflected field. The type of the method handle will have a void return type. If the field is static, the method handle will take a single argument, of the field's value type, the value to be stored. Otherwise, the two arguments will be the instance containing the field, and the value to be stored. If the field's`accessible`flag is not set, access checking is performed immediately on behalf of the lookup class.

If the field is static, and if the returned method handle is invoked, the field's class will be initialized, if it has not already been initialized.

<br />

|                Parameters                ||
|-----|-------------------------------------|
| `f` | `Field`: the reflected field <br /> |

|                                                                            Returns                                                                            ||
|---------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can store values into the reflected field <br /> |

|                                                            Throws                                                            ||
|----------------------------------------------------------------------------------------------------|--------------------------|
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if the argument is null  |

### unreflectSpecial

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public MethodHandle unreflectSpecial (Method m, 
                Class<?> specialCaller)
```

Produces a method handle for a reflected method. It will bypass checks for overriding methods on the receiver,[as if called](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#equiv)from an`invokespecial`instruction from within the explicitly specified`specialCaller`. The type of the method handle will be that of the method, with a suitably restricted receiver type prepended. (The receiver type will be`specialCaller`or a subtype.) If the method's`accessible`flag is not set, access checking is performed immediately on behalf of the lookup class, as if`invokespecial`instruction were being linked.

Before method resolution, if the explicitly specified caller class is not identical with the lookup class, or if this lookup object does not have[private access](https://developer.android.com/reference/java/lang/invoke/MethodHandles.Lookup#privacc)privileges, the access fails.

The returned method handle will have[variable arity](https://developer.android.com/reference/java/lang/invoke/MethodHandle#asVarargsCollector(java.lang.Class<?>))if and only if the method's variable arity modifier bit (`0x0080`) is set.

<br />

|                               Parameters                                ||
|-----------------|--------------------------------------------------------|
| `m`             | `Method`: the reflected method <br />                  |
| `specialCaller` | `Class`: the class nominally calling the method <br /> |

|                                                                       Returns                                                                       ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------|
| [MethodHandle](https://developer.android.com/reference/java/lang/invoke/MethodHandle) | a method handle which can invoke the reflected method <br /> |

|                                                                                                     Throws                                                                                                      ||
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails or if the method's variable arity modifier bit is set and`asVarargsCollector`fails |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if any argument is null                                                                                     |

### unreflectVarHandle

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VarHandle unreflectVarHandle (Field f)
```

Produces a VarHandle giving access to a reflected field`f`of type`T`declared in a class of type`R`. The VarHandle's variable type is`T`. If the field is non-static the VarHandle has one coordinate type,`R`. Otherwise, the field is static, and the VarHandle has no coordinate types.

Access checking is performed immediately on behalf of the lookup class, regardless of the value of the field's`accessible`flag.

If the field is static, and if the returned VarHandle is operated on, the field's declaring class will be initialized, if it has not already been initialized.

Certain access modes of the returned VarHandle are unsupported under the following conditions:

- if the field is declared`final`, then the write, atomic update, numeric atomic update, and bitwise atomic update access modes are unsupported.
- if the field type is anything other than`byte`,`short`,`char`,`int`,`long`,`float`, or`double`then numeric atomic update access modes are unsupported.
- if the field type is anything other than`boolean`,`byte`,`short`,`char`,`int`or`long`then bitwise atomic update access modes are unsupported.

If the field is declared`volatile`then the returned VarHandle will override access to the field (effectively ignore the`volatile`declaration) in accordance to its specified access modes.

If the field type is`float`or`double`then numeric and atomic update access modes compare values using their bitwise representation (see[Float.floatToRawIntBits](https://developer.android.com/reference/java/lang/Float#floatToRawIntBits(float))and[Double.doubleToRawLongBits](https://developer.android.com/reference/java/lang/Double#doubleToRawLongBits(double)), respectively).

<br />

##### API Note:

- Bitwise comparison of`float`values or`double`values, as performed by the numeric and atomic update access modes, differ from the primitive`==`operator and the[Float.equals](https://developer.android.com/reference/java/lang/Float#equals(java.lang.Object))and[Double.equals](https://developer.android.com/reference/java/lang/Double#equals(java.lang.Object))methods, specifically with respect to comparing NaN values or comparing`-0.0`with`+0.0`. Care should be taken when performing a compare and set or a compare and exchange operation with such values since the operation may unexpectedly fail. There are many possible NaN values that are considered to be`NaN`in Java, although no IEEE 754 floating-point operation provided by Java can distinguish between them. Operation failure can occur if the expected or witness value is a NaN value and it is transformed (perhaps in a platform specific manner) into another NaN value, and thus has a different bitwise representation (see[Float.intBitsToFloat](https://developer.android.com/reference/java/lang/Float#intBitsToFloat(int))or[Double.longBitsToDouble](https://developer.android.com/reference/java/lang/Double#longBitsToDouble(long))for more details). The values`-0.0`and`+0.0`have different bitwise representations but are considered equal when using the primitive`==`operator. Operation failure can occur if, for example, a numeric algorithm computes an expected value to be say`-0.0`and previously computed the witness value to be say`+0.0`.

|                                             Parameters                                              ||
|-----|------------------------------------------------------------------------------------------------|
| `f` | `Field`: the reflected field, with a field of type`T`, and a declaring class of type`R` <br /> |

|                                                                         Returns                                                                          ||
|---------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| [VarHandle](https://developer.android.com/reference/java/lang/invoke/VarHandle) | a VarHandle giving access to non-static fields or a static field <br /> |

|                                                            Throws                                                            ||
|----------------------------------------------------------------------------------------------------|--------------------------|
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) | if access checking fails |
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException)     | if the argument is null  |