Skip to content

Instantly share code, notes, and snippets.

@muthuishere
Created August 17, 2021 05:42
Show Gist options
  • Save muthuishere/8aa8115ce18b2faa1329044ffd04f9a9 to your computer and use it in GitHub Desktop.
Save muthuishere/8aa8115ce18b2faa1329044ffd04f9a9 to your computer and use it in GitHub Desktop.
Default value
results= Try.from(()->newsService.downloadFromNyTimes(topic))
.or(()->newsService.downloadFromHerald(topic))
.or(()->newsService.downloadFromSun(topic))
.get();
// since the for the above case it will be null
// if you would like to get default value
results= Try.from(()->newsService.downloadFromNyTimes(topic))
.or(()->newsService.downloadFromHerald(topic))
.or(()->newsService.downloadFromSun(topic))
.orElseGet(Arrays.asList("Default News for topic x","Default News for topic Y"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment