Old
// Risky: get() throws if empty, no clear intent
String value = optional.get();
// Verbose: supplier just for NoSuchElementException
String value = optional
.orElseThrow(NoSuchElementException::new);
Modern
// Clear intent: throws NoSuchElementException if empty
String value = optional.orElseThrow();
hover to see modern →