我想生成一些如下代码:
AbstractSomeClass<?> someClassObj = new AbstractSomeClass<MyConcreteType> {
...
}
我尝试了以下方法:
JDefinedClass anonymousSomeClass = codeModel.anonymousClass(AbstractSomeClass.class);
...
conditionalBody.decl(anonymousSomeClass, "someClassObj", JExpr._new(anonymousSomeClass.narrow(jClass)));
下面出现异常,由“anonymousSomeClass.narrow(jClass)”引起。如果我删除'.narrow(jClass)',一切都会好起来的。
java.lang.NullPointerException
at com.sun.codemodel.JDefinedClass.outer(JDefinedClass.java:776)
at com.sun.codemodel.JFormatter.t(JFormatter.java:280)
at com.sun.codemodel.JNarrowedClass.generate(JNarrowedClass.java:143)
at com.sun.codemodel.JFormatter.g(JFormatter.java:350)
at com.sun.codemodel.JInvocation.generate(JInvocation.java:173)
at com.sun.codemodel.JFormatter.g(JFormatter.java:350)
at com.sun.codemodel.JVar.bind(JVar.java:212)
at com.sun.codemodel.JFormatter.b(JFormatter.java:396)
at com.sun.codemodel.JVar.declare(JVar.java:216)
...
谢谢。