调用合约lambda表达式写法报错
Opened this issue · 2 comments
glowwormX commented
demo每次调用合约需要新写一个类,尝试lambda表达式写法,org.apache.bcel.util
报找不到类错误
//调用 注册
//Transaction transaction1 = new Transaction.HVMBuilder(account.getAddress()).invoke(contractAddress, new InvokeStudentReg()).build();
//使用lambda表达式,避免新写一个类
BaseInvoke<String, IStudent> register = iStudent ->
iStudent.registerStudent(Arrays.asList(new Student("id1", "name1", 20), new Student("id2", "name2", 20)));
Transaction transaction1 = new Transaction.HVMBuilder(account.getAddress()).invoke(contractAddress, register).build();
transaction1.sign(account);
ReceiptResponse receiptResponse1 = contractService.invoke(transaction1).send().polling();
String decodeHVM1 = Decoder.decodeHVM(receiptResponse1.getRet(), String.class);
System.out.println("decode: " + decodeHVM1);
System.out.println(receiptResponse1.getRet());
报错:
java.lang.RuntimeException: java.lang.ClassNotFoundException: TestStudent$$Lambda$9/18179709 not found.
at cn.hyperchain.sdk.common.utils.Encoder.encodeInvokeBeanJava(Encoder.java:97)
at cn.hyperchain.sdk.transaction.Transaction$HVMBuilder.invoke(Transaction.java:173)
at TestStudent.invoke(TestStudent.java:62)
taoyq1988 commented
This problem is because Lambda expressions will generate additional classes. If you write Lambda expressions in InvokeBean, the class information may not be found, and the encoding fails. You can use other methods to replace Lambda, sorry. @glowwormX
glowwormX commented
sdk最好支持此种写法,未来有计划支持么