Download Jar. Uses 755K of libraries. Click here for Pure Java version (5029L/28K).
!7 lib 1400554 // javassist import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; p { ClassPool pool = ClassPool.getDefault(); CtClass cc = pool.makeClass("User123"); // The method part doesn't work yet /*CtClass cString = pool.get("java.lang.String"); var method = new CtMethod(cString, "hello", new CtClass[0], cc); method.setModifiers(Modifier.PUBLIC | Modifier.STATIC); cc.addMethod(method);*/ //Class c = cc.toClass(); byte[] bytes = cc.toBytecode(); var cl = new InMemoryClassLoader(myClassLoader()); Class c = cl.defineAClass("User123", bytes); print(c); }
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034295 |
Snippet name: | Test Javassist (make class at runtime, higher level API) |
Eternal ID of this version: | #1034295/6 |
Text MD5: | 9cc90d2a86be0c4ead30c2395ffcf699 |
Transpilation MD5: | 5795b037514a1afcf4ae78e5181930ba |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-01 15:06:10 |
Source code size: | 642 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 194 / 795 |
Version history: | 5 change(s) |
Referenced in: | #1034298 - Test Javassist (bytecode level API, dev.) |