dynamic-class-creation

How can I test a .class file was created?

谁说我不能喝 提交于 2019-12-04 19:22:33
I want to unit test my code which will have to create a .java file compile it and then the corresponding .class file should be created. How can I create the test to see if the ".class" file is created? I have added test already for its existence, now I'm trying to test the file is a valid class file. I tried try { Class.forName("Hello"); throw AssertError(); } catch( ClassNotFoundException e ) { } program.createClass(); Class.forName("Hello"); But I don't really know how to dynamically add the path where the file is created to the classpath. EDIT URL Class loaded does the work. This is how my

Java: Strong Code mobility How to?

折月煮酒 提交于 2019-12-04 05:16:00
Does anyone know how to use Java for Strong code mobility ? Have you ever done it before? Here's what I try to achieve. Suppose we have 2 separate Java applications that communicate over network. App A and App B. App A has a class x instantiated as an object, and has been using it. App B has no prior knowledge of this class x. App A needs to migrate the instance of class x over to App B. App B should be able to dynamically load class x, and retains the state of class x. I have Googled around and found a bunch of resources on how to dynamically load class at run-time. However, I'm not sure if

How to dynamically create a class?

。_饼干妹妹 提交于 2019-11-26 03:13:38
问题 I have a class which looks like this: public class Field { public string FieldName; public string FieldType; } And an object List<Field> with values: {\"EmployeeID\",\"int\"}, {\"EmployeeName\",\"String\"}, {\"Designation\",\"String\"} I want to create a class that looks like this: Class DynamicClass { int EmployeeID, String EmployeeName, String Designation } Is there any way to do this? I want this to be generated at runtime. I don\'t want a physical CS file residing in my filesystem. 回答1: