File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 sourceCode.append(" public String hello() { return \"hello\"; }");
1616 sourceCode.append("}");
1717
18- Class<?> helloClass = InMemoryJavaCompiler.compile("org.mdkt.HelloClass", sourceCode.toString());
19-
20- Alternatively, if you want to load several (dependent) classes:
21-
22- String cls1 = "public class A{ public B b() { return new B(); }}";
23- String cls2 = "public class B{ public String toString() { return \"B!\"; }}";
24-
25- InMemoryJavaCompiler compiler = new InMemoryJavaCompiler();
26- compiler.addSource("A", cls1);
27- compiler.addSource("B", cls2);
28- Map<String,Class<?>> compiled = compiler.compileAll();
29-
30- Class<?> aClass = compiled.get("A");
31-
18+ Class<?> helloClass = InMemoryJavaCompiler.newInstance().compile("org.mdkt.HelloClass", sourceCode.toString());
3219
3320Artifact is pushed to Sonatype OSS Releases Repository
3421
You can’t perform that action at this time.
0 commit comments