Stream.map(...).reduce() as string joiner: error "left-hand side" [message #1807642] |
Wed, 05 June 2019 09:44  |
Eclipse User |
|
|
|
Hello,
I found this JSF EL expression on the net:
<h:outputText value="#{companyBenutzerManager.selectedEntity.zulassungen.stream().map( zul -> zul.client.name ).reduce( ( p1, p2 ) -> p1 += ', ' += p2 ).get()}" />
What this does is simply produce a comma-separated list of client names to be displayed in a dialog - in one line. ;-)
I need the same on my bean however, to send an e-mail with this text. I then copied the line and changed it to pure Java like:
String str = getSelectedEntity().getZulassungen().stream().map( zul -> zul.getClient().getName() ).reduce( ( p1, p2 ) -> p1 += ", " += p2 ).get();
However, this doesn't compile.
Why?
The error in Eclipse is:
"The left-hand side of an assignment must be a variable"
Also see attachment.
Note, that I changed the code a little for better understanding.
Does anyone know why this shows an error in Eclipse? Why is it working in JSF EL but not in Java?
Thanks
Karsten
|
|
|
|
Re: Stream.map(...).reduce() as string joiner: error "left-hand side" [message #1807704 is a reply to message #1807667] |
Thu, 06 June 2019 09:25  |
Eclipse User |
|
|
|
Yeah, now that you say it...
String str = getSelectedEntity().getZulassungen().stream().map( zul -> zul.getClient().getName() ).reduce( ( p1, p2 ) -> p1 += ", " + p2 ).get();
Indeed += seems to something I had not expected. Changing the concat operator from += to + works.
Strange.
Thanks for helping on this.
[Updated on: Thu, 06 June 2019 09:26] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.53215 seconds