Tôi đã cố gắng tạo một số mã động (Sử dụng Javassist) nhưng chương trình không thành công tại một điểm nhất định khi liên quan đến mảng kép hoặc mảng float. Mã này là như sauXác minh lỗi: không phù hợp args_size cho opc_invokeinterface
Class c = Customers.class; // called in main & Customer class just has a double[] Dubs = new double[10]
CreateType(c); // Main
public static Object CreateType(Class genericType)
{
// some preReq declarations
CtMethod writeCode = dyn.getDeclaredMethod("processCode");
generateCode(genericType, Code, "temp"); // Code is a StringBuilder class
System.out.println(Code);
writeCode.insertAt(1, Code.toString()); // Compilation is successful
Class c = dyn.toClass();
Dynamic h;
Constructor[] ctorlist = null;
ctorlist = c.getDeclaredConstructors(); // Problem is here
h = (DynamicSurrogate) ctorlist[0].newInstance(genericType);
return h;
}
Tạo mã như sau
testapp1.Customers temp=(testapp1.Customers)graph;
output.processDouble(temp.Dubs[1]);
Nhưng vấn đề nảy sinh khi getDeclaredConstructors được gọi c.getDeclaredConstructors() ... nó ném các lỗi sau
ngoại lệ trong thread "main" java.lang.VerifyError: (class: testapp1/Dyn, phương thức: processDouble signature: (Lsomething/Output; Ljava/lang/Object;) V) Không phù hợp args_size cho opc_invokeinterface
.210Một cách giải quyết tồn tại nhưng không thực hiện bất kỳ nghĩa nào đó, tức là tất cả mọi thứ hoạt động tốt nếu tôi chỉ đơn giản là tạo ra một bản sao của mảng đôi và vượt qua nó trên để processDouble trong mã năng động tức là nếu mã năng động là
testapp1.Customers temp=(testapp1.Customers)graph;
double[] d = temp.Dubs;
output.processDouble(d);
Trong ngắn, ngoại lệ Unhandled được ném bởi getDeclaredConstructor nhưng nó thực sự không có gì để làm với một constructor vì nó không quan trọng nếu tôi tạo một hoặc không
Hy vọng rằng vấn đề và mã của tôi là đủ rõ ràng, nếu có nhầm lẫn xin vui lòng cho biết, Thankyou in trước :)