Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8059324

orElseThrow has different signatures for OptionalPrimitive and Optional<T>

XMLWordPrintable

    • b50
    • x86
    • windows_8

        FULL PRODUCT VERSION :


        A DESCRIPTION OF THE PROBLEM :
        The signature of OptionalInt.orElseThrow is
        <X extends Throwable> int orElseThrow(Supplier<X> exceptionSupplier) throws X;

        Similarly, the signature of OptionalDouble.orElseThrow is
        <X extends Throwable> double orElseThrow(Supplier<X> exceptionSupplier) throws X;

        and the signature of OptionalLong.orElseThrow is
        <X extends Throwable> long orElseThrow(Supplier<X> exceptionSupplier) throws X;

        The signature of Optional<T>.orElseThrow, however, is
        public<X extends Throwable> int orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;

        I believe that Supplier<? extends X> is redundant, in which case it should be only Supplier<X>, as in OptionalInt, OptionalDouble, and OptionalLong.

        If there is a reason for Supplier<? extends X> in Optional<T>, then the Supplier for OptionalInt, OptionalDouble, and OptionalLong should also be a Supplier<? extends X>



        REPRODUCIBILITY :
        This bug can be reproduced always.

              psandoz Paul Sandoz
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: