@@ -0,0 +1,1366 @@
+package laol.rt;%0A%0Aimport java.lang.invoke.MethodHandle;%0Aimport static java.lang.invoke.MethodHandles.publicLookup;%0Aimport java.lang.invoke.MethodType;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0A/**%0A *%0A * @author kpfalzer%0A */%0Apublic class Test2 %7B%0A    public static class B %7B%0A        %0A    %7D%0A    %0A    public static class C extends B %7B%0A        public B f1(int a) %7B%0A            m_val += a;%0A            return this;%0A        %7D%0A        %0A        private int m_val = 0;%0A    %7D%0A    %0A    %0A    public static void main(String argv%5B%5D) %7B%0A        C c = new C();%0A        B b = c.f1(3);%0A        b = c;%0A        %0A        /** We can't compile this%0A        B x = b.f1(5);%0A        * We need to do dynamic dispatch...%0A        * b.getClass().getMethods()...%0A        */%0A        assert (b instanceof C);%0A        %0A        try %7B%0A            MethodHandle f1 = publicLookup().findVirtual(b.getClass(), %22f1%22, MethodType.methodType(B.class, int.class));%0A            B b2 = (B)f1.invokeExact((C)b, 123);%0A            //%0A            Object b3 = f1.invoke(b, 123);%0A            boolean debug = true;%0A        %7D catch (NoSuchMethodException %7C IllegalAccessException ex) %7B%0A            Logger.getLogger(Test2.class.getName()).log(Level.SEVERE, null, ex);%0A        %7D catch (Throwable ex) %7B%0A            Logger.getLogger(Test2.class.getName()).log(Level.SEVERE, null, ex);%0A        %7D%0A    %7D%0A%7D%0A

add example dynamic dispatch to rt