I saw how you answered my comment, but itβs still not clear to me why you want to generate the code, which will then be packaged in a jar, just enter it :)
Now, if you want typeafe api with the whole method to have the same behavior, you could provide a dynamic proxy for this interface (this leaves you with a question about how to generate the interface :)
Here is an example where all calls to the entire MyInterface method will be handled by the invoke method (just add methods to the interface to test it) ...
package test; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; public class Test { interface MyInterface { String methodOne(String s); String methodTwo(String s, Integer i); } static MyInterface proxy = (MyInterface) Proxy.newProxyInstance( MyInterface.class.getClassLoader(), new Class[] { MyInterface.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { StringBuilder result = new StringBuilder(); for (Object arg : args) { result.append(arg.toString()); } return result.toString(); } }); public static void main(String[] args) { System.out.println(proxy.methodOne("hello")); System.out.println(proxy.methodTwo("world", 5)); } }
pgras
source share