TODAY Method Invoker - Java 字节码级别方法调用


GPL
跨平台
Java

软件简介

TODAY Method Invoker 是一个 Java 字节码级别方法调用。

使用说明

public class TestHandlerInvoker {

    public static void main(String[] args) throws Exception {

        System.setProperty("cglib.debugLocation", "D:/debug");
        {
            final Method main = Bean.class.getDeclaredMethod("main");
            final Invoker mainInvoker = MethodInvokerCreator.create(main);
            mainInvoker.invoke(null, null);
        }
        {
            final Method test = Bean.class.getDeclaredMethod("test", short.class);
            final Invoker mainInvoker = MethodInvokerCreator.create(test);
            mainInvoker.invoke(null, new Object[] { (short) 1 });
        }

        final Invoker create = MethodInvokerCreator.create(Bean.class, "test");
        create.invoke(new Bean(), null);
        final Invoker itself = MethodInvokerCreator.create(Bean.class, "test", Bean.class);
        itself.invoke(new Bean(), new Object[] { new Bean() });
    }

    public static class Bean {

        public static void test(short i) throws Throwable {
            System.err.println("static main " + i);
        }

        protected static void main() throws Throwable {
            System.err.println("static main");
        }

        public void test() throws Throwable {
            System.err.println("instance test");
        }

        void test(Bean itself) {
            System.err.println("instance test :" + itself);
        }
    }
}