如何从内部静态类扩展生成的类?
例如,我有
class Foo {
static class Bar {
}
}
我希望我生成的类从 Bar 扩展
JCodeModel codeModel = new JCodeModel()
JClass aClass = codeModel.ref("somePckg.Foo$Bar")
JPackage jp = codeModel._package("pckag")
JDefinedClass jc = jp._class("GeneratedClass")
jc._extends(aClass)
codeModel.build(new File("generated/"))
我得到的是
import somePckg.Foo$Bar;
public class GeneratedClass extends Foo$Bar {}
但我想要的是
import somePckg.Foo;
public class GeneratedClass extends Foo.Bar {}
解决方案:
你应该像这样传递类名:
codeModel.ref("android.support.v7.widget.RecyclerView.ViewHolder")
CodeModel 会生成
package pckg;
import somePckg.Foo.Bar;
public class GeneratedClass extends Bar {
}