Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33961
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Lambda reference? |
| Date | Mon, 14 Mar 2016 17:16:05 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 59 |
| Message-ID | <nc79gr$9e6$1@dont-email.me> (permalink) |
| References | <nc770d$u97$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Mon, 14 Mar 2016 21:12:59 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="9670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hdaKeDaYdg+yj5YQiut7A" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <nc770d$u97$1@dont-email.me> |
| Cancel-Lock | sha1:hBKPaevtCqRuhqWfMIjtJjUBRhY= |
| Xref | csiph.com comp.lang.java.programmer:33961 |
Show key headers only | View raw
On 3/14/2016 4:32 PM, Rhino wrote:
> I'm just new to Java Lambda expressions. I'm both excited and frustrated
> by the Oracle tutorials describing them: the tutorial shows how powerful
> they are and that's got me keen to know more but I'm not finding the
> detailed references I need to be able to do what I want to do.
> [...]
See Sebastian's response. I'd just like to add that lambdas and
streams are two different things, and that you may confuse yourself
if you try to conflate them. Lambda expressions are often useful with
streams, but you can use streams without them. Streams are frequent
users of lambda expressions, but lambda expressions have non-stream
uses as well.
Here's a fragment using a lambda, with no stream (or collection)
anywhere in sight:
gadget.addActionListener((evt) -> {
... do something with the ActionEvent ...
});
... which we used to have to write as:
gadget.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
... do something with the ActionEvent ...
}
});
And here's a stream operation with no lambda in the neighborhood:
Predicate<Thing> pred = new Predicate<>() {
@Override
public boolean test(Thing thing) {
... long, complicated computation ...
return answer;
}
};
List<Thing> theChosenFew = allThings.stream()
.filter(pred)
.collect(Collectors.toList());
... which we might have lambda-ized (if it's not too bulky):
List<Thing> theChosenFew = allThings.stream()
.filter((thing) -> {
... long, complicated computation ...
return answer;
})
.collect(Collectors.toList());
So: Although they are frequently used together, try to bear in
mind that there's no "necessary" connection between lambda expressions
and stream operations.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Lambda reference? Rhino <no_offline_contact@example.com> - 2016-03-14 16:32 -0400
Re: Lambda reference? Sebastian <news@seyweiler.dyndns.org> - 2016-03-14 21:50 +0100
Re: Lambda reference? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-14 17:16 -0400
Re: Lambda reference? Rhino <no_offline_contact@example.com> - 2016-03-14 18:29 -0400
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-16 04:53 -0700
Re: Lambda reference? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-16 08:38 -0400
Re: Lambda reference? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-03-16 08:45 -0400
Re: Lambda reference? Sebastian <news@seyweiler.dyndns.org> - 2016-03-16 21:33 +0100
Re: Lambda reference? Robert Klemme <shortcutter@googlemail.com> - 2016-03-25 18:35 +0100
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-28 07:06 -0700
Re: Lambda reference? Robert Klemme <shortcutter@googlemail.com> - 2016-03-31 00:09 +0200
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-31 04:42 -0700
Re: Lambda reference? Robert Klemme <shortcutter@googlemail.com> - 2016-03-31 18:35 +0200
Re: Lambda reference? Eric Douglas <e.d.programmer@gmail.com> - 2016-03-31 11:21 -0700
Re: Lambda reference? Rhino <no_offline_contact@example.com> - 2016-03-14 21:55 -0400
csiph-web