A DESCRIPTION OF THE PROBLEM :
Introduce a convenience method T Optional.orNull() as a more readable alternative to repetitive Optional.orElse(null) calls.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
When interoperating with APIs that accept or require null, developers frequently write:
Optional.orElse(null)
Add the following method to java.util.Optional:
/**
* Returns the value if present, otherwise returns {@code null}.
*
* <p>This is a convenience method equivalent to {@code orElse(null)}.
*
* @return the contained value if present, otherwise {@code null}
*/
public T orNull() {
return value;
}
FREQUENCY :
ALWAYS
Introduce a convenience method T Optional.orNull() as a more readable alternative to repetitive Optional.orElse(null) calls.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
When interoperating with APIs that accept or require null, developers frequently write:
Optional.orElse(null)
Add the following method to java.util.Optional:
/**
* Returns the value if present, otherwise returns {@code null}.
*
* <p>This is a convenience method equivalent to {@code orElse(null)}.
*
* @return the contained value if present, otherwise {@code null}
*/
public T orNull() {
return value;
}
FREQUENCY :
ALWAYS
- duplicates
-
JDK-8171200 java.util.Optional should have a "T orNull()"
-
- Closed
-