• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

ExecutorService and execute Runnable  RSS feed

 
Ranch Hand
Posts: 74
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi all,
I don't understand why line #3 is compiling without any problem. There is only one execute() method in ExecutorService which takes a Runnable, and Runnable run() returns void.
Line #3 shouldn't compile because toString() has an incompatible return type. But it does.
Line #4 does not compile, the compiler error is: bad return type in Lambda expression.
Thank you, Juerg
 
Bartender
Posts: 9494
184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Functional interfaces that have a void return type can always be implemented by lambda expressions that have a statement as their body. Even if that statement is a method call with a return type, the return type is simply ignored.

#3 compiles because rid.toString() is a statement.
#4 does not compile because "TestRiddle" is not a statement.

For the same reason, you can do this:
And not this:
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!