--- old/src/java.base/share/classes/java/util/OptionalInt.java 2017-12-07 15:57:38.000000000 -0800 +++ new/src/java.base/share/classes/java/util/OptionalInt.java 2017-12-07 15:57:38.000000000 -0800 @@ -117,14 +117,10 @@ * {@code NoSuchElementException}. * * @apiNote - * The methods {@link #orElse(int) orElse} and - * {@link #orElseGet(IntSupplier) orElseGet} - * are generally preferable to this method, as they return a substitute - * value if the value is absent, instead of throwing an exception. + * The preferred alternative to this method is {@link #orElseThrow()}. * * @return the value described by this {@code OptionalInt} * @throws NoSuchElementException if no value is present - * @see OptionalInt#isPresent() */ public int getAsInt() { if (!isPresent) { @@ -225,6 +221,21 @@ } /** + * If a value is present, returns the value, otherwise throws + * {@code NoSuchElementException}. + * + * @return the value described by this {@code OptionalInt} + * @throws NoSuchElementException if no value is present + * @since 10 + */ + public int orElseThrow() { + if (!isPresent) { + throw new NoSuchElementException("No value present"); + } + return value; + } + + /** * If a value is present, returns the value, otherwise throws an exception * produced by the exception supplying function. *