1

assume that I have this String : and i need to generate a class of it inside another class ? Kindly any one have a suggestion for this ?**

 String sourceCode = "public class Test {   " +
        "public void myMethod(@Mandatory String s){"+
        "System.out.println( \"myMethod : \"+s);}"+


 "@SuppressWarnings(\"unused\")"+
 "private void mySecondMethod(String s2){"+
    "System.out.println(\"mySecondMethod : \"+s2);}"+ 

 "}";   
1

2 Answers 2

1

You can generate java classes dynamically using Java Compiler API

http://www.accordess.com/wpblog/an-overview-of-java-compilation-api-jsr-199/

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the JavaCompiler.

There are examples in the link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.