This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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
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".
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!