Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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
Pie
Posts: 6503
83
  • 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