• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question regarding return values from Callable & Runnable (Sybex)

 
Greenhorn
Posts: 21
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I don't understand the following on page 344:

 //2ND LAMBDA EXPRESSION DOES NOT COMPILE

The explanation why the 2nd line doesn't compile is as follows: The lambda expression does not return a value, therefore, the compiler treats this as a Runnable expression. But the submit(Runnable) method DOES return a value:
Future<?> submit(Runnable task). So I don't understand this explanation, seeing that both submit(Runnable) and submit(Callable) return a value (Future). How do you separate both? This is also explicitly stated on page 339:

        => returns a Future representing the task.
   => returns a Future representing the pending results of the task.

Can someone please help me with this?

Thanks in advance!

 
Helene Shaikh
Greenhorn
Posts: 21
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind, I've answered my own question
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the benefit of anyone else reading this, Thread.sleep method throws a checked exception. The call method in Callable declares a throws clause of Exception. But the run method of Runnable doesn't, so the second Lambda expression doesn't compile...
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Helene Shaikh wrote:Nevermind, I've answered my own question


It's great when that happens.

Note: I added the publisher to your subject line. That way it is obvious to anyone reading which OCP book this about.) And welcome to CodeRanch!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Helene Shaikh wrote:Nevermind, I've answered my own question


It would have been awesome and cow-worthy if you had shared your answer with the community... And another additional benefit: if your answer would not be 100% accurate, other ranchers could have made the necessary comments/corrections on your answer. So it would be a very informative experience for us all
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic