Lambda compatibility and checked exceptions

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 8
    • Affects Version/s: 8
    • Component/s: tools
    • b100

      The following program does not compile:

      interface F<T extends Throwable> {
         void m() throws T;
      }

      <Z extends Throwable> m(F<Z> fz) { ... }

      m(()->{ }); //error

      The problem is caused by the fact that inferred type for Z defaults to the declared bound as no other constraints comes up when examining the lambda body. This causes the 'm' to be instantiated as a Throwable-throwing method, thus requiring the user to catch the exception with a try-catch block. This is completely unnecessary as it can be seen that the lambda doesn't throw any checked exception.

            Assignee:
            Maurizio Cimadamore
            Reporter:
            Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: