tag:blogger.com,1999:blog-4815481734454081491.post7403570263383227718..comments2023-10-24T02:15:03.269-07:00Comments on Minborg's Java Pot: Put Your Java 8 Method References to WorkPer Minborghttp://www.blogger.com/profile/08526963148025854611noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-4815481734454081491.post-3563970441219138122017-09-11T09:32:09.050-07:002017-09-11T09:32:09.050-07:00Casting can be used but I think it does not look s...Casting can be used but I think it does not look so good. You would need to write <br /><br /><br />Stream.of("A", "", "B").filter(((Predicate<String>)String::isEmpty).negate()).count();<br /><br />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!Per Minborghttps://www.blogger.com/profile/08526963148025854611noreply@blogger.comtag:blogger.com,1999:blog-4815481734454081491.post-53429413271472922432017-09-11T06:49:55.456-07:002017-09-11T06:49:55.456-07:00Actually, Java provides a simple way to do this - ...Actually, Java provides a simple way to do this - the explicit cast:<br /><br /> Stream.of("A", "", "B").filter(((Predicate)String::isEmpty).negate()).count();Kundahttps://www.blogger.com/profile/10580857047673332436noreply@blogger.comtag:blogger.com,1999:blog-4815481734454081491.post-44255260974373398522017-09-05T09:47:03.878-07:002017-09-05T09:47:03.878-07:00Yes. I think this is also a good way to do it. Tha...Yes. I think this is also a good way to do it. Thanks for you suggestion.Per Minborghttps://www.blogger.com/profile/08526963148025854611noreply@blogger.comtag:blogger.com,1999:blog-4815481734454081491.post-82711638240475205542017-09-05T02:01:36.708-07:002017-09-05T02:01:36.708-07:00Why not just have a "not" like this:
...Why not just have a "not" like this: <br /><br /> public static final T Predicate T not( Predicate T predicate ) {<br /> return predicate.negate();<br /> }<br /><br />This you can use like: <br /><br /> Stream.of("A", "", "B").filter(not(String::isEmpty)).count();<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4815481734454081491.post-85677614262508844422017-07-27T21:22:46.259-07:002017-07-27T21:22:46.259-07:00"as(String::isEmpty).negate()"
That'..."as(String::isEmpty).negate()"<br /><br />That's pretty brilliant. A real shame that java doesn't offer a simple way to do this.. seems like a pretty obvious need.Unknownhttps://www.blogger.com/profile/07128596996835697637noreply@blogger.com