Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38190
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte.net> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Lambda dereference |
| Date | Sat, 17 Mar 2018 03:10:21 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 43 |
| Message-ID | <p8htfh$p2r$1@dont-email.me> (permalink) |
| References | <p8h2a1$4f0$1@dont-email.me> <p8h2lu$773$1@dont-email.me> <slrnpaolja.5mg.avl@logic.at> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sat, 17 Mar 2018 02:10:57 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="dbb58620834cbaa6e79112940118b9eb"; logging-data="25691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//Ik4b8cCA22wXMRw2VILL" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
| In-Reply-To | <slrnpaolja.5mg.avl@logic.at> |
| X-Antivirus-Status | Clean |
| Content-Language | en-GB |
| X-Antivirus | AVG (VPS 180316-4, 03/16/2018), Outbound message |
| Cancel-Lock | sha1:yDM3K4v5/Vmky9I+nwjzG1g6X5w= |
| Xref | csiph.com comp.lang.java.programmer:38190 |
Show key headers only | View raw
On 2018-03-17 00:42, Andreas Leitgeb wrote:
> Daniele Futtorovic <da.futt.news@laposte.net> wrote:
>> On 2018-03-16 19:26, Daniele Futtorovic wrote:
>>> interface Tagged {
>>> boolean tag();
>>> }
>>> Stream<Tagged> stream = ...;
>>> You can do this (exhibit A):
>>> Predicate<Tagged> p = Tagged::tag;
>>> Collection<Tagged> untagged = stream.filter( p.negate()
>>> ).collect(Collectors.toSet());
>>> But you can't do this (exhibit B):
>>> Collection<Tagged> untagged = stream.filter( (Tagged::tag).negate()
>>> ).collect(Collectors.toSet());
>>> Why not? It would be pretty neat. Or am I missing something?
>>
>> This works:
>> Collection<Tagged> untagged = stream.filter(
>> ((Predicate<Tagged>)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)?
>
No, absolutely -- the compiler can't determine that Tagged::tag is a
Predicate without the context, and hence (Tagged::tag).negate() will
fail (parentheses just for clarification). I'd figured as much, but then
when I tried to add a cast, I didn't seem to be going anywhere. So I
thought, hey, that's something I could post to cljp! And when it was
posted, I thought, just a second, I'd better double-check some more.
And, oh fortuna, thou art a bitch, the cast worked.
Foot.values().forEach( Mouth.get()::insert ); :-/
--
DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Lambda dereference Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-16 19:26 +0100
Re: Lambda dereference Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-16 19:32 +0100
Re: Lambda dereference Andreas Leitgeb <avl@logic.at> - 2018-03-16 23:42 +0000
Re: Lambda dereference Daniele Futtorovic <da.futt.news@laposte.net> - 2018-03-17 03:10 +0100
csiph-web