Share via


MethodHandles.Constant(Class, Object) Method

Definition

Produces a method handle of the requested return type which returns the given constant value every time it is invoked.

[Android.Runtime.Register("constant", "(Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)]
public static Java.Lang.Invoke.MethodHandle? Constant (Java.Lang.Class? type, Java.Lang.Object? value);
[<Android.Runtime.Register("constant", "(Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=26)>]
static member Constant : Java.Lang.Class * Java.Lang.Object -> Java.Lang.Invoke.MethodHandle

Parameters

type
Class

the return type of the desired method handle

value
Object

the value to return

Returns

a method handle of the given return type and no arguments, which always returns the given value

Attributes

Remarks

Produces a method handle of the requested return type which returns the given constant value every time it is invoked.

Before the method handle is returned, the passed-in value is converted to the requested type. If the requested type is primitive, widening primitive conversions are attempted, else reference conversions are attempted.

The returned method handle is equivalent to identity(type).bindTo(value).

Java documentation for java.lang.invoke.MethodHandles.constant(java.lang.Class<?>, java.lang.Object).

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