,
void m(Predicate<String> stringPredicate)
class Utilities {
static boolean condition1(String s) { ... }
static boolean condition2(String s) { ... }
...
}
m , , Utilities.condition1 . Java
m(Utilities::condition1)
but no
m(Utilities::condition1.negate())
(unfortunately, violation of referential transparency ), and the compiler complained: "A reference to the Java method is not expected here."
My workaround was to write a method
Predicate<String> not(Predicate<String> p) {
return p;
}
and then write a call
m(not(Utilities::condition1))
--which is allowed by Java grammar.
source
share