我正在玩JCodeModel并尝试生成一个类;多亏了这个链接,我才能想出这个:
public final class CodeModelTest
{
private CodeModelTest()
{
throw new Error("no instantiation is permitted");
}
public static void main(final String... args)
throws JClassAlreadyExistsException, IOException
{
final JCodeModel model = new JCodeModel();
final JDefinedClass c = model._class("foo.bar.Baz");
c._extends(BaseParser.class);
final JMethod method = c.method(JMod.PUBLIC, Rule.class, "someRule");
method.body()._return(JExpr._null());
final CodeWriter cw = new OutputStreamCodeWriter(System.out,
StandardCharsets.UTF_8.displayName());
model.build(cw);
}
}
所以,这行得通。标准输出上生成的代码是:
package foo.bar;
import com.github.fge.grappa.parsers.BaseParser;
import com.github.fge.grappa.rules.Rule;
public class Baz
extends BaseParser
{
public Rule someRule() {
return null;
}
}
到目前为止,一切都很好。
现在,问题是我想extends BaseParser<Object>
而不是BaseParser
......尽管在谷歌上搜索了好几个小时,但我无法弄清楚如何做到这一点......
我该怎么做呢?