繁体   English   中英

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

[英]JavaPoet : How to add a field of type class , but I have only the class name, not the class?

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;

任何其他解决方法也表示赞赏。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM