Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试向 TypeSpec 添加一个内部类(例如接口 Listener{})。我还想在我的 TypeSpec 中添加一个 Listener 类型的字段。我怎么能做到这样的事情?
TypeSpec outerClass = ...; TypeSpec innerClass = ...; outerClass.addType(innerClass); outerClass.addField(...); // How can i add a field of type innerClass?
您需要计算类型的完全限定名称。看起来像这样:
ClassName outerName = ClassName.get("com.example.project", "Outer"); ClassName innerName = outerName.nestedClass("Inner");
然后你可以调用outerClass.addField()pass innerName。
outerClass.addField()
innerName