Download Jar. Uses 1311K of libraries. Click here for Pure Java version (9648L/46K).
!7 set flag AllPublic. p { ClassMaker<IF0> c = new(IF0); // make code for get() method var m = new MethodMaker(c.cg, O, "get"); // declare and create StringBuffer int buffer = m.newLocalVar(); m.newObject(StringBuffer.class).astore(buffer); // Append two strings for (string : ll("Hello ", "world")) { m.aload(buffer).stringConstant(string); m.il.append(m.factory.createAppend(org.apache.bcel.generic.Type.OBJECT)); } // call StringBuffer.toString() and return m.aload(buffer); m.invokeVirtual(StringBuffer.class, S, "toString"); m.areturn().done(); // disassemble because it looks cool c.printClassWithMethods(); // bake class, load & create instance IF0 f = c.newInstance(); print(f); assertEqualsVerbose("Hello world", f!); }
Began life as a copy of #1034311
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034315 |
Snippet name: | Test making class implementing interface from scratch with BCEL using ClassMaker + MethodMaker [OK] |
Eternal ID of this version: | #1034315/4 |
Text MD5: | 94051bcb8c7120cfe0e9da46447e39d4 |
Transpilation MD5: | 26fb1cd25b3db54e9b03ddcb1b91bb09 |
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 20:58:33 |
Source code size: | 850 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 216 / 810 |
Version history: | 3 change(s) |
Referenced in: | [show references] |