I am trying out method reference inside forEach
private static void printConditionally8(List<Person> people, Predicate<Person> predicate) {
people.forEach(p-> { if (predicate.test(p)){
System.out.println("Print here");}
});
}
Above works fine but I want to make it more short using methods reference however its giving compilation problem.Is there any way to make it happen ?
private static void printConditionally8(List<Person> people, Predicate<Person> predicate) {
people.forEach({ if (predicate::test){
System.out.println("Print here");}
});
}