No Parameters

Description

For a lambda expression with no parameters, we still need the parentheses.

() -> { System.out.println("hi"); }

Example

The following example shows how to use BooleanSupplier.


import java.util.function.BooleanSupplier;
//from   www  . ja v  a  2 s .  c  om
public class Main {
  public static void main(String[] args) {
    BooleanSupplier bs = () -> true;
    System.out.println(bs.getAsBoolean());

    int x = 0, y= 1;
    bs = () -> x > y;
    System.out.println(bs.getAsBoolean());
  }
}

The code above generates the following result.





















Home »
  Java Lambda »
    Java Lambda Tutorial »




Java Lambda Tutorial