[英]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.