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

Surprising behavior with more than one functional interface on a class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • core-libs
    • None
    • b81
    • generic
    • generic

        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

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

                Created:
                Updated:
                Resolved: