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

Surprising more-specific results for lambda bodies with no return expressions

    Details

    • Subcomponent:
    • Resolved In Build:
      b102
    • Verification:
      Not verified

      Description

      As pointed out in JDK-8037788, the specification of more-specific function type return types fails to account for the possibility that the a lambda body has no return expressions. javac has the same problem, causing many types are considered "more specific" than many others, even when this is illogical. The effect is surprising ambiguities and surprising explanations for ambiguities.

      The following should succeed under both the current spec, and as revised by JDK-8037788, but produces an error:

      interface I { Object run(); }
      interface J { String run(); }

      void m(I arg) {}
      void m(J arg) {}

      void test() {
          m(() -> { throw new RuntimeException(); });
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: