• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Core Java for the Impatient - Chapter 8 Streams question  RSS feed

 
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Chapter 8, there's a section called How Not To Work With Optional values.

Can you summarize in one sentence what are the gotchas to watch out for when designing and using APIs that exposes optional values ?

As far as I'm concerned, nulls in the JVM is an impediment to using java.util.Optional ? It applies to Enums as well.

P.S. The book contains too much introductory material for me to fork out the money for it.
 
author
Ranch Hand
Posts: 232
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, if you already know Java, then Core Java for the Impatient isn't for you. To quickly cut to the chase of Java 8, check out Java SE 8 for the Really Impatient (http://horstmann.com/java8/)

For an API designer, there isn't much mystery about Optional. Just return an Optional<T> instead of a "T or null".

For the consumer of such an API, the key insight is not to use the isPresent or get methods. Instead, use orElse, ifPresent, or chain a consuming function with flatMap.

Cheers,

Cay
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I'll take a look at "Java 8 for the Really Impatient".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!