Class OptionalOrElseThrowExamples
java.lang.Object
net.jrodolfo.java_evolution.java10.OptionalOrElseThrowExamples
Demonstrates the no-argument
Optional.orElseThrow() method added in
Java 10.
Before Java 10, callers commonly used get() or the Java 8
orElseThrow(Supplier) overload. get() was short but did not
communicate intent well. The supplier overload was explicit but verbose when
the default NoSuchElementException was acceptable.
Java 10 added a clearer no-argument option for that common case.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondescribeRequiredFeature(String featureName) Looks up a feature by name and unwraps the result with no-argOptional.orElseThrow().requiredValue(Optional<String> value) Returns the value when the Optional is present.
-
Constructor Details
-
OptionalOrElseThrowExamples
public OptionalOrElseThrowExamples()
-
-
Method Details
-
requiredValue
-
describeRequiredFeature
Looks up a feature by name and unwraps the result with no-argOptional.orElseThrow().- Parameters:
featureName- the feature to find- Returns:
- a message for the requested feature
-