Java Magazine, Sept/Oct 2017
Java 9 Core Library Updates Optionals and CompletableFutures Changes to Optional and CompletableFuture help you better model error cases for business applications ORACLE COM JAVAMAGAZINE SEPTEMBER OCTOBER 2017 33 java 9 In the previous article on Java 9 s changes Java 9 Core Library Updates Collections and Streams we showed that there were lots of goodies that make developers more productive on a day to day basis Java 9 isnt just about big picture improvements such as modules and the Java 9 read eval print loop REPL In this article we complete the examination of major changes to core libraries by looking at improvements to the Optional and CompletableFuture APIs Optional Optional a feature introduced in Java 8 to facilitate work with streams was updated in Java 9 This release introduced the features discussed here stream ifPresentOrElse and or stream If youve been using Java 8 s Stream API in conjunction with the Optional class you might have encountered a situation in which you wanted to replace a stream of Optionals with values For example suppose you have a collection of settings that might have been set by a user Youve implemented the following lookupSettingByName method which returns an Optional Setting if the configuration setting has been set by the user List Setting settings SETTING_ NAMES stream map this lookupSettingByName filter Optional isPresent map Optional get collect toList RAOUL GABRIEL URMA RICHARD WARBURTON
You must have JavaScript enabled to view digital editions.