-
-
Save nokok/c6af486d88c769b8180d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import javassist.CannotCompileException; | |
import javassist.ClassPool; | |
import javassist.CtClass; | |
import javassist.CtMethod; | |
import javassist.CtNewMethod; | |
public class CreateHappyNewYear { | |
public static void main(String[] args) throws IOException, CannotCompileException { | |
ClassPool classPool = ClassPool.getDefault(); | |
CtClass happyNewYearClazz = classPool.makeClass("HappyNewYear"); | |
CtMethod method = CtNewMethod.make("public static void main(String[] args){"+ | |
"System.out.println(\"Happy New Year!\");" + | |
"}", happyNewYearClazz); | |
happyNewYearClazz.addMethod(method); | |
happyNewYearClazz.writeFile("."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment