Java 10

Published: Friday, 3 July 2020

Java 10 changes

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();