我想生成一个新类,如下所示:
public class QueryBuilder_QueryField
extends AbstractQueryBuilder<QueryBuilder_QueryField>
我尝试了这个但是它并没有缩小扩展范围...
JCodeModel model = new JCodeModel();
String fqcn = packageName + "." + className;
JDefinedClass builderClass = model._class(fqcn);
builderClass._extends(AbstractQueryBuilder.class).narrow(builderClass);
但最终却像
public class QueryBuilder_QueryField
extends AbstractQueryBuilder
有任何想法吗?
最佳答案
我相信您需要先缩小范围,然后再将类传递给_extends()
:
JCodeModel model = new JCodeModel();
String fqcn = packageName + "." + className;
JDefinedClass builderClass = model._class(fqcn);
builderClass._extends(model.ref(AbstractQueryBuilder.class).narrow(builderClass));
产生:
public class QueryBuilder_QueryField
extends AbstractQueryBuilder<QueryBuilder_QueryField>