@Test public void testConsumer() { Consumer<String> anonymousClass = new Consumer<String>() { @Override public void accept(String s) { System.out.println(s.toUpperCase()); } }; Consumer<String> lambda = s -> System.out.println(s.toUpperCase()); LambdaExamples.useConsumer(anonymousClass); LambdaExamples.useConsumer(lambda); LambdaExamples.useConsumer(s -> System.out.println(s.toUpperCase())); }
public static void useConsumer(Consumer<String> consumer){ String foo = "foo"; System.out.println("Before consumer"); consumer.accept(foo); System.out.println("After consumer"); }
LambdaExamples { public static void useConsumer(Consumer<String> consumer){ String foo = "foo"; System.out.println("Before consumer"); consumer.accept(foo); System.out.println("After consumer"); } }
LambdaExamples { public static void useConsumer(Consumer<String> consumer){ String foo = "foo"; System.out.println("Before consumer"); consumer.accept(foo); System.out.println("After consumer"); }  }
LambdaExamples { public static void useConsumer(Consumer<String> consumer){ String foo = "foo"; System.out.println("Before consumer"); consumer.accept(foo); System.out.println("After consumer"); }  static void useRunnable(Runnable runnable); static void useConsumer(Consumer<String> consumer); static String usePredicate(Predicate<String> predicate); static int useFunction(Function<String, Integer> function); }
LambdaExamples { public static void useConsumer(Consumer<String> consumer){ String foo = "foo"; System.out.println("Before consumer"); consumer.accept(foo); System.out.println("After consumer"); }  static void useRunnable(Runnable runnable); static void useConsumer(Consumer<String> consumer); static String usePredicate(Predicate<String> predicate); static int useFunction(Function<String, Integer> function);  }