Add Predicate.of(), Consumer.of(), etc. (original) (raw)
Paul Sandoz paul.sandoz at oracle.com
Wed May 6 10:37:34 UTC 2015
- Previous message: Add Predicate.of(), Consumer.of(), etc.
- Next message: Add Predicate.of(), Consumer.of(), etc.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On May 2, 2015, at 11:31 PM, Remi Forax <forax at univ-mlv.fr> wrote:
Hi all, today, I stubble on a variant of JDK-8050818 [1], trying to call negate() on a lambda which is not yet a Predicate (due to target typing) which requires either to cast the lambda to a Predicate and everybody knows that cast are evil or to add a local variable.
I think there is a way to fix that, it's not very orthodox so I let you judge. The idea is to introduce a static method 'of' on Predicate, class Predicate { ... public static Predicate of(Predicate predicate) { return predicate; } } so one can write: stream.filter(Predicate.of(String::isEmpty).negate()) compared to stream.filter(((Predicate)String::isEmpty).negate()) so the question is, does it it worth the cost to introduce a static method that basically do nothing on all functional interfaces of java.util.function.
That does have the virtue of not adding a static method per operation but i still cannot bring myself to add such methods as a work around for seems like a compiler inference problem (albeit one in which might be very tricky or not possible to solve).
In some respects i wonder if the default methods on the functional interfaces are an attractive nuisance.
Paul.
- Previous message: Add Predicate.of(), Consumer.of(), etc.
- Next message: Add Predicate.of(), Consumer.of(), etc.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]