词条 | JRuntime |
释义 |
name = JRuntime | developer = Helion-Prime Solutions Ltd. | latest_release_version = 1.0 | latest_release_date = {{release date|2008|06|24}} | operating_system = Cross-platform | programming_language = Java | genre = Library | license = GNU Lesser General Public License | website = JRuntime Home Page }} JRuntime is the simple library for Java. It makes easier an access to Java 6 compiler API. This library enables compiling, executing and modifying Java-code dynamically while the program is working. UsageDynamic class compilationString classDef = "public class MyClass {"+ " public String toString() {" + " return \\"MyClass\\";" + " }"+ "}";RuntimeClass runtimeClass = new RuntimeClass(classDef);System.out.println(runtimeClass.newInstance()); Dynamic block executionRuntimeBlock sum = new RuntimeBlock( "return (Integer)params[0]+(Integer)params[1];");System.out.println(sum.invoke(1, 2));System.out.println(sum.invoke(5, 100)); Dynamic class modificationpublic class ClassToModify { public String simpleMethod(String text) { System.out.println("Text: " + text); return text; }}...MutableRuntimeClass<ClassToModify> clazz = new MutableRuntimeClass<ClassToModify>(ClassToModify.class);ClassToModify instance = clazz.newInstance(new SimpleMutator() { @Override public void onBeforeMethod(Object instance, Method method, Object... params) { System.out.println("Before method: " + method.getName() + ", params: " + Arrays.toString(params)); } @Override public Object onAfterMethod(Object instance, Method method, Object result, Object... params) { System.out.println("After method: " + method.getName() + ", params: " + Arrays.toString(params)); return result; }});instance.simpleMethod("Test mutable class!!!"); External links
1 : Java (programming language) libraries |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。