Interface IfThenElse

  • All Known Implementing Classes:
    IfThenElseImpl

    public interface IfThenElse
    An if-then-else construct.

    This construct is not thread-safe and should not be re-used.

    • Method Detail

      • elseIf

        BytecodeCreator elseIf​(ResultHandle condition)
        Creates a new else-if statement. The block is executed if the condition result handle is evaluated as true.

        Note that the condition result handle must already exist.

         boolean test = foo.testIsOk();
         if (someOtherCondition) {
             // do action "A"
         } else if (test) {
             // do action "B"
         }
         
        If you need to create the condition result handle inside the if-else statement then use the elseIf(Function) method instead.
        Parameters:
        condition -
        Returns:
        the else-if block
      • elseIf

        BytecodeCreator elseIf​(java.util.function.Function<BytecodeCreator,​ResultHandle> test)
        Creates a new else-if statement. The block is executed if the condition result handle returned from the function is evaluated as true.

        The argument of the function represents the block that is executed when the else-if statement is evaluated.

        In order to generate the bytecode for the "action B" branch in the following example:

         if (someOtherCondition) {
             // do action "A"
         } else if (foo.testIsOk()) {
             // do action "B"
         }
         
        The code needs to look like:
         IfThenElse ifAction = method.ifThenElse(someOtherCondition);
         BytecodeCreator ifTestOk = ifValue.elseIf(b -> b.invokeVirtualMethod(testIsOkMethodDescriptor, fooInstance)));
         // do action "B"
         
        Parameters:
        test -
        Returns:
        the else-if block
      • elseThen

        BytecodeCreator elseThen()
        This block is executed if no condition result handle was evaluated as true.
        Returns:
        the else block