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

Lambda Spec: Handle when nominal/structural most-specific disagree

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • None
    • specification
    • Verified

    Description

      In a case of two functional interface declarations like the following, most-specific should not claim that one type is better than the other (for an explicit lambda):

      interface T2 {
       String apply(int arg);
      }

      interface T1 extends T2 {
       default String apply(int arg) { return "x"; }
       Object get(int arg);
      }

      void m(T1 arg);
      void m(T2 arg);

      m((int x) -> "a"); // ambiguous

      T1 is "nominally" better, but T2 is "structurally" better. So neither one is clearly the better choice, which is what most-specific is looking for.

      In contrast, for an implicit lambda, no structural comparison is made, and so the subtype (T2) should be preferred.

      m(x -> "a"); // resolve to m(T2)

      Attachments

        Issue Links

          Activity

            People

              dlsmith Dan Smith
              dlsmith Dan Smith
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: