Hi Jim,
here is my review,
the target should use a wildcard,
static <T> Predicate<T> not(Predicate<? super T> target) {
return ...
}
Due to a limitation of the inference, 'return target.negate()' will not compile.
One may think that, we should write
static <T> Predicate<T> not(Predicate<? super T> target) {
return t -> !target.test(t);
}
but if the class of 'target' override negate(), we will not call it.
So the right code seems to be
@SuppressWarnings("unchecked") // Predicate is contra-variant
static <T> Predicate<T> not(Predicate<? super T> target) {
return (Predicate<T>)target.negate();
}
at least until JEP 300 [1] is implemented.
regards,
Rémi
[1] https://bugs.openjdk.java.net/browse/JDK-8043488
----- Mail original -----
> De: "Jim Laskey" <[email protected]>
> À: "core-libs-dev" <[email protected]>
> Envoyé: Vendredi 18 Mai 2018 18:35:24
> Objet: RFR: CSR - JDK-8203428 Predicate::not
> Introduce a new static method Predicate::not which will allow developers to
> negate predicate lambdas trivially.
>
>
> csr: https://bugs.openjdk.java.net/browse/JDK-8203428