Partager via


MethodHandles.Lookup.Bind(Object, String, MethodType) Method

Definition

Produces an early-bound method handle for a non-static method.

[Android.Runtime.Register("bind", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)]
public Java.Lang.Invoke.MethodHandle Bind (Java.Lang.Object receiver, string name, Java.Lang.Invoke.MethodType type);
[<Android.Runtime.Register("bind", "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)>]
member this.Bind : Java.Lang.Object * string * Java.Lang.Invoke.MethodType -> Java.Lang.Invoke.MethodHandle

Parameters

receiver
Object

the object from which the method is accessed

name
String

the name of the method

type
MethodType

the type of the method, with the receiver argument omitted

Returns

the desired method handle

Attributes

Remarks

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 MethodHandle#asVarargsCollector variable arity if and only if the method's variable arity modifier bit (0x0080) is set <em>and</em> 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: <blockquote>

{@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;
            }

</blockquote> 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.)

Java documentation for java.lang.invoke.MethodHandles.Lookup.bind(java.lang.Object, java.lang.String, java.lang.invoke.MethodType).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to