RFR 8059324: orElseThrow has different signatures for OptionalPrimitive and Optional<T>

Chris Hegarty chris.hegarty at oracle.com
Wed Jan 21 13:19:04 UTC 2015


On 20/01/15 16:56, Paul Sandoz wrote:
> Hi,
>
> http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8059324-Optional-orElseThrow-signatures/webrev/

Looks ok to me.

> The patch fixes up the signatures of Optional{Int, Long, Double}.orElseThrow to be consistent with Optional.orElseThrow.
>
> I believe this is a compatible change since the classes are final.

That is my understanding also. And you are expanding the set of 
acceptable suppliers.

-Chris.

> I will also file a CCC.
>
> Paul.
>
> diff -r 8b8b84397c5a src/java.base/share/classes/java/util/OptionalDouble.java
> --- a/src/java.base/share/classes/java/util/OptionalDouble.java Tue Jan 20 16:35:19 2015 +0000
> +++ b/src/java.base/share/classes/java/util/OptionalDouble.java Tue Jan 20 16:54:07 2015 +0000
> @@ -182,7 +182,7 @@
>        * @throws NullPointerException if no value is present and
>        * {@code exceptionSupplier} is null
>        */
> -    public<X extends Throwable> double orElseThrow(Supplier<X> exceptionSupplier) throws X {
> +    public<X extends Throwable> double orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
>           if (isPresent) {
>               return value;
>           } else {
> diff -r 8b8b84397c5a src/java.base/share/classes/java/util/OptionalInt.java
> --- a/src/java.base/share/classes/java/util/OptionalInt.java    Tue Jan 20 16:35:19 2015 +0000
> +++ b/src/java.base/share/classes/java/util/OptionalInt.java    Tue Jan 20 16:54:07 2015 +0000
> @@ -182,7 +182,7 @@
>        * @throws NullPointerException if no value is present and
>        * {@code exceptionSupplier} is null
>        */
> -    public<X extends Throwable> int orElseThrow(Supplier<X> exceptionSupplier) throws X {
> +    public<X extends Throwable> int orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
>           if (isPresent) {
>               return value;
>           } else {
> diff -r 8b8b84397c5a src/java.base/share/classes/java/util/OptionalLong.java
> --- a/src/java.base/share/classes/java/util/OptionalLong.java   Tue Jan 20 16:35:19 2015 +0000
> +++ b/src/java.base/share/classes/java/util/OptionalLong.java   Tue Jan 20 16:54:07 2015 +0000
> @@ -182,7 +182,7 @@
>        * @throws NullPointerException if no value is present and
>        * {@code exceptionSupplier} is null
>        */
> -    public<X extends Throwable> long orElseThrow(Supplier<X> exceptionSupplier) throws X {
> +    public<X extends Throwable> long orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
>           if (isPresent) {
>               return value;
>           } else {
>



More information about the core-libs-dev mailing list