@Test public void testPredicate() { Predicate<String> anonymousClass = new Predicate<String>() { @Override public boolean test(String s) { return s.length() > 5; } }; Predicate<String> lambda = s -> s.toUpperCase().equals("FOO"); assertNull(LambdaExamples.usePredicate(anonymousClass)); assertNotNull(LambdaExamples.usePredicate(lambda)); assertNotNull(LambdaExamples.usePredicate(s -> { int length = s.length(); return length == 3; } )); }
public static String usePredicate(Predicate<String> predicate){ String foo = "foo"; if(predicate.test(foo)){ return foo; } else { return null; } }
LambdaExamples { public static String usePredicate(Predicate<String> predicate){ String foo = "foo"; if(predicate.test(foo)){ return foo; } else { return null; } } }
LambdaExamples { public static String usePredicate(Predicate<String> predicate){ String foo = "foo"; if(predicate.test(foo)){ return foo; } else { return null; } }  }
LambdaExamples { public static String usePredicate(Predicate<String> predicate){ String foo = "foo"; if(predicate.test(foo)){ return foo; } else { return null; } }  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 String usePredicate(Predicate<String> predicate){ String foo = "foo"; if(predicate.test(foo)){ return foo; } else { return null; } }  static void useRunnable(Runnable runnable); static void useConsumer(Consumer<String> consumer); static String usePredicate(Predicate<String> predicate); static int useFunction(Function<String, Integer> function);  }