Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Stream.map(...).reduce() as string joiner: error "left-hand side"
Stream.map(...).reduce() as string joiner: error "left-hand side" [message #1807642] Wed, 05 June 2019 13:44 Go to next message
Karsten Wutzke is currently offline Karsten WutzkeFriend
Messages: 117
Registered: July 2009
Senior Member
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 #1807667 is a reply to message #1807642] Wed, 05 June 2019 21:09 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3462
Registered: July 2009
Senior Member

This is more a general Java question than an Eclipse question.

+= may be a valid string concatenation operator in JSF EL, but it means something very different in Java. You can't assign a new value to the literal " ,".


Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Stream.map(...).reduce() as string joiner: error "left-hand side" [message #1807704 is a reply to message #1807667] Thu, 06 June 2019 13:25 Go to previous message
Karsten Wutzke is currently offline Karsten WutzkeFriend
Messages: 117
Registered: July 2009
Senior Member
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 13:26]

Report message to a moderator

Previous Topic:Update of the Eclipse founder's edition not possible
Next Topic:Dealing with spaces in file paths when building
Goto Forum:
  


Current Time: Sun Aug 18 02:31:15 GMT 2019

Powered by FUDForum. Page generated in 0.02969 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top