Java 10
Java 10 changes
Section titled “Java 10 changes”Optional orElseThrow
Section titled “Optional orElseThrow”orElseThrow() has been added to Optional as a replacement for get(). It has the same behaviour but has clearer naming.
If the value is present it will be returned, otherwise a NoSuchElementException is thrown.
.findFirst().orElseThrow();