Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Andreas Leitgeb Newsgroups: comp.lang.java.programmer Subject: Re: Lambda dereference Date: Fri, 16 Mar 2018 23:42:34 -0000 (UTC) Organization: A noiseless patient Spider Lines: 28 Message-ID: References: Reply-To: avl@logic.at Injection-Date: Fri, 16 Mar 2018 23:42:34 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="3a3884ccceae22bb6fb71e31c0f31fd7"; logging-data="7281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vwlCjRP3l9vV/21HqYZyP" User-Agent: slrn/1.0.2 (Linux) Cancel-Lock: sha1:E6iG9GlHJxS5aX6ikRSyIO6VVPI= Xref: csiph.com comp.lang.java.programmer:38189 Daniele Futtorovic wrote: > On 2018-03-16 19:26, Daniele Futtorovic wrote: >> interface Tagged { >> boolean tag(); >> } >> Stream stream = ...; >> You can do this (exhibit A): >> Predicate p = Tagged::tag; >> Collection untagged = stream.filter( p.negate() >> ).collect(Collectors.toSet()); >> But you can't do this (exhibit B): >> Collection untagged = stream.filter( (Tagged::tag).negate() >> ).collect(Collectors.toSet()); >> Why not? It would be pretty neat. Or am I missing something? > > This works: > Collection untagged = stream.filter( > ((Predicate)Tagged::tag).negate() ).collect(Collectors.toSet()); > > ... and it makes sense why it wouldn't accept it without the casting. Huh, why? Well, Java does have some "expressions" that only work as initializers (like braced list of elements for initializing arrays), but that wouldn't look to me like such a case - afterall one could use Tagged::tag right there if it weren't for the ".negate()". What would be the expression type of blank (Tagged::tag)?