In Java, I have only ever defined "method references" Function
and BiFunction
w/ lambda expressions, like so:
private static Function<Integer, Boolean> IsEvenFunc =
(i) -> (i % 2 == 0);
private static BiFunction<String, Character, Boolean> ByFirstCharFunc =
(s, c) -> (s.charAt(0) == c.charValue());
CustomList<Integer> numbers = new CustomList<>();
numbers.append(9);
numbers.append(42);
numbers.append(47);
System.out.println(numbers.toStringBy(IsEvenFunc));
CustomList<String> names = new CustomList<>();
names.append("Joe");
names.append("Jim");
names.append("Bob");
System.out.println(names.toStringBy(ByFirstCharFunc, 'J'));
However, for teaching purposes, if my students don't yet know lambda syntax, is it possible to create these Function
and BiFunction
methods without lambda expressions?
Something like...?
private static BiFunction<String s, Character c, Boolean> ByFirstCharFunc
{
return s.charAt(0) == c.charValue();
}