I have already created an empty class SimpleClass. How can I generate some code in this class in runtime and recompile the class to be able to use that code?
public class SimpleClass {}
I've found the solution with generating whole class with it's content using custom ClassLoader and javax.tools API.
But is there any for existing class?
public class SimpleClass {
//Generated code in runtime
public void method() {
System.out.println("Generated method");
}
}
public class SimpleClass { private String f1; private String f2; private String f3; public void useF1() { // do some action with f1 } public void useF2() { // do some action with f2 } public void useF3() { // do some action with f3 } }public void useF(String fieldName) { // do some action with field with name - fieldName }