JavaPoet:如何添加类型为class的字段,但是我只有类名,而没有类?

时间:2018-10-12 09:12:50

标签: java javapoet

String fieldName = (fieldchild.getAttribute("Name")); //gives field name : opcode

String fieldCustomID = (fieldchild.getAttribute("ID")); //gives id: 2022

String classTypeofField = IdNameMappingList.get(fieldCustomID).toString(); //give class name OpCodeClass

FieldSpec fieldSpec = FieldSpec.builder(**some code**, fieldName)
                                                        .build();

应提供类似的内容:

OpCodeClass opcode;

其他解决方法也受到赞赏。

1 个答案:

答案 0 :(得分:0)

尝试ClassName.get("com.company.app", classTypeofField),将包名称替换为该类的名称。