Comments on: Put Your Java 8 Method References to Work https://speedment.com/put-your-java-8-method-references-to-work/ Build Fast Java Applications for the Fastest Business Performance Fri, 01 May 2020 05:21:37 +0000 hourly 1 https://wordpress.org/?v=5.1.1 By: Per Minborg https://speedment.com/put-your-java-8-method-references-to-work/#comment-78 Mon, 11 Sep 2017 16:32:09 +0000 https://speedment.com/put-your-java-8-method-references-to-work/#comment-78 Casting can be used but I think it does not look so good. You would need to write

Stream.of("A", "", "B").filter(((Predicate<String>)String::isEmpty).negate()).count();

if you do not want compiler warnings and it is a bit cluttery. But that is my personal opinion only. I should have mentioned cast in the article. Thanks for your comment!

]]>
By: Kunda https://speedment.com/put-your-java-8-method-references-to-work/#comment-79 Mon, 11 Sep 2017 13:49:55 +0000 https://speedment.com/put-your-java-8-method-references-to-work/#comment-79 Actually, Java provides a simple way to do this – the explicit cast:

Stream.of("A", "", "B").filter(((Predicate)String::isEmpty).negate()).count();

]]>
By: Per Minborg https://speedment.com/put-your-java-8-method-references-to-work/#comment-80 Tue, 05 Sep 2017 16:47:03 +0000 https://speedment.com/put-your-java-8-method-references-to-work/#comment-80 Yes. I think this is also a good way to do it. Thanks for you suggestion.

]]>
By: Anonymous https://speedment.com/put-your-java-8-method-references-to-work/#comment-81 Tue, 05 Sep 2017 09:01:36 +0000 https://speedment.com/put-your-java-8-method-references-to-work/#comment-81 Why not just have a "not" like this:

public static final T Predicate T not( Predicate T predicate ) {
return predicate.negate();
}

This you can use like:

Stream.of("A", "", "B").filter(not(String::isEmpty)).count();

]]>
By: Unknown https://speedment.com/put-your-java-8-method-references-to-work/#comment-87 Fri, 28 Jul 2017 04:22:46 +0000 https://speedment.com/put-your-java-8-method-references-to-work/#comment-87 "as(String::isEmpty).negate()"

That's pretty brilliant. A real shame that java doesn't offer a simple way to do this.. seems like a pretty obvious need.

]]>