This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When return statement is required in block (Lambda )

 
Nil. Hatamova
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It confused me when i must use return statement in lamda expressions. Is it required or optional? In Study Guide (Jeanne and Scott) said return is required in block. Also they said there is compile error because of return in this code:


But there are some questions in Ethuware about select correct lambda expressions. The correct answers are lambda expressions without return statement. Only with semi-colons like this:

So i dont catch when i must use return in block
 
Stephan van Hulst
Bartender
Posts: 6646
90
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use return in a block when the method that the lambda implements has a return type other than void.

It looks like the processList() method requires a BiConsumer. The BiConsumer.accept() method returns void.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!