Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38189
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Andreas Leitgeb <avl@logic.at> |
| 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 | <slrnpaolja.5mg.avl@logic.at> (permalink) |
| References | <p8h2a1$4f0$1@dont-email.me> <p8h2lu$773$1@dont-email.me> |
| 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 |
Show key headers only | View raw
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)?
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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