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

Javadoc of MethodHandles.Lookup::bind should note the difference from MethodHandle::bindTo

    XMLWordPrintable

Details

    • b170
    • Not verified

    Backports

      Description

        Javadoc of MethodHandles.Lookup::bind describes its relation to the MethodHandle::bindTo. Specifically, it says
            (Note that {@code bindTo} does not preserve variable arity.)

        JDK-8177146 introduced another difference: in the example below 'bind' throws IllegalAccessException but 'bindTo' throws ClassCastException.
        That should be noted in the Javadoc.

        Example:
        =================================
        public class B extends A {
            public static void main(String[] args) throws Throwable {
                // throws IAE
                MethodHandle bound2 = lookup().bind(new A() , "m", MethodType.methodType(void.class));

                // throws CCE
                lookup().findVirtual(A.class, "m", MethodType.methodType(void.class))
                        .bindTo(new A());
            }
        }

        package pkg;
        public class A {
            protected void m() { }
        }
        =================================

        Attachments

          Issue Links

            Activity

              People

                psandoz Paul Sandoz
                slukyanov Stanislav Lukyanov (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: