src/share/classes/java/util/Optional.java
Print this page
rev 8107 : 8025610: Add explicit @throws NPE documentation to Optional constructor and Optional.of
Reviewed-by: duke
*** 83,92 ****
--- 83,93 ----
/**
* Constructs an instance with the value present.
*
* @param value the non-null value to be present
+ * @throws NullPointerException if value is null
*/
private Optional(T value) {
this.value = Objects.requireNonNull(value);
}
*** 94,103 ****
--- 95,105 ----
* Returns an {@code Optional} with the specified present non-null value.
*
* @param <T> the class of the value
* @param value the value to be present, which must be non-null
* @return an {@code Optional} with the value present
+ * @throws NullPointerException if value is null
*/
public static <T> Optional<T> of(T value) {
return new Optional<>(value);
}