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

Surprising behavior with more than one functional interface on a class

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b81
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Currently we link invocations of @FunctionalInterface methods with an "instanceof <declaring interface>" guard. This seems like a nice stable linkage but can produce weird behavior with classes that implement multiple functional interfaces. Currently, the functional method of the first functional interface of the latest-linked object will dominate earlier-linked ones in that call site. To illustrate:

        var fc = new (Java.extend(java.util.function.Function, java.util.function.Consumer))({
            apply: function(x) { print("fc invoked as a function") },
            accept: function(x) { print("fc invoked as a consumer") }
        });
        var c = new java.util.function.Consumer(function(x) { print("c invoked as a consumer") });
        for each(x in [fc, c, fc]) { x(null); }

        prints:

        fc invoked as a function
        c invoked as a consumer
        fc invoked as a consumer

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  sundar Sundararajan Athijegannathan
                  Reporter:
                  attila Attila Szegedi
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: