public class Example { public static void main(String[] args) throws Exception { Eventloop eventloop = Eventloop.create().withCurrentThread(); ActiveJGenerator generator = new ActiveJGenerator() .generateClass("ExampleClass") .withField("String", "name") .withMethod("void", "printHello", methodBuilder -> methodBuilder .addStatement("System.out.println(\"Hello, \" + name + \"!\")") ); Class<?> exampleClass = generator.loadClass(); Object instance = exampleClass.getDeclaredConstructor().newInstance(); Method printHelloMethod = exampleClass.getDeclaredMethod("printHello", null); printHelloMethod.invoke(instance, null); } }


上一篇:
下一篇:
切换中文