MethodHandles.WhileLoop(MethodHandle, MethodHandle, MethodHandle) Method

Definition

Constructs a while loop from an initializer, a body, and a predicate.

[Android.Runtime.Register("whileLoop", "(Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=33)]
public static Java.Lang.Invoke.MethodHandle? WhileLoop (Java.Lang.Invoke.MethodHandle? init, Java.Lang.Invoke.MethodHandle? pred, Java.Lang.Invoke.MethodHandle? body);
[<Android.Runtime.Register("whileLoop", "(Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;)Ljava/lang/invoke/MethodHandle;", "", ApiSince=33)>]
static member WhileLoop : Java.Lang.Invoke.MethodHandle * Java.Lang.Invoke.MethodHandle * Java.Lang.Invoke.MethodHandle -> Java.Lang.Invoke.MethodHandle

Parameters

init
MethodHandle

optional initializer, providing the initial value of the loop variable. May be null, implying a default initial value. See above for other constraints.

pred
MethodHandle

condition for the loop, which may not be null. Its result type must be boolean. See above for other constraints.

body
MethodHandle

body of the loop, which may not be null. It controls the loop parameters and result type. See above for other constraints.

Returns

a method handle implementing the while loop as described by the arguments.

Attributes

Remarks

Constructs a while loop from an initializer, a body, and a predicate. This is a convenience wrapper for the #loop(MethodHandle[][]) generic loop combinator.

The pred handle describes the loop condition; and body, its body. The loop resulting from this method will, in each iteration, first evaluate the predicate and then execute its body (if the predicate evaluates to true). The loop will terminate once the predicate evaluates to false (the body will not be executed in this case).

The init handle describes the initial value of an additional optional loop-local variable. In each iteration, this loop-local variable, if present, will be passed to the body and updated with the value returned from its invocation. The result of loop execution will be the final value of the additional loop-local variable (if present).

The following rules hold for these argument handles:<ul> <li>The body handle must not be null; its type must be of the form (V A...)V, where V is non-void, or else (A...)void. (In the void case, we assign the type void to the name V, and we will write (V A...)V with the understanding that a void type V is quietly dropped from the parameter list, leaving (A...)V.) <li>The parameter list (V A...) of the body is called the <em>internal parameter list</em>. It will constrain the parameter lists of the other loop parts. <li>If the iteration variable type V is dropped from the internal parameter list, the resulting shorter list (A...) is called the <em>external parameter list</em>. <li>The body return type V, if non-void, determines the type of an additional state variable of the loop. The body must both accept and return a value of this type V. <li>If init is non-null, it must have return type V. Its parameter list (of some form <c>(A*)</c>) must be effectively identical to the external parameter list (A...). <li>If init is null, the loop variable will be initialized to its #empty default value. <li>The pred handle must not be null. It must have boolean as its return type. Its parameter list (either empty or of the form (V A*)) must be effectively identical to the internal parameter list. </ul>

The resulting loop handle's result type and parameter signature are determined as follows:<ul> <li>The loop handle's result type is the result type V of the body. <li>The loop handle's parameter types are the types (A...), from the external parameter list. </ul>

Here is pseudocode for the resulting loop handle. In the code, V/v represent the type / value of the sole loop variable as well as the result type of the loop; and A/a, that of the argument passed to the loop. <blockquote>

{@code
            V init(A...);
            boolean pred(V, A...);
            V body(V, A...);
            V whileLoop(A... a...) {
              V v = init(a...);
              while (pred(v, a...)) {
                v = body(v, a...);
              }
              return v;
            }
            }

</blockquote>

Added in 9.

Java documentation for java.lang.invoke.MethodHandles.whileLoop(java.lang.invoke.MethodHandle, java.lang.invoke.MethodHandle, java.lang.invoke.MethodHandle).

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