无法在codemodel中创建抽象类?

时间:2016-06-23 06:53:55

标签: sun-codemodel

我的代码:

JCodeModel cm = new JCodeModel();
cm._class(JMod.ABSTRACT, "TestClass", ClassType.CLASS);
cm.build(new File("."));

无论我写入modsClassType参数,结果始终为public class

如何创建抽象类?

1 个答案:

答案 0 :(得分:1)

奇怪。似乎JCodeModel没有包没有创建抽象类。以下案例有一个包声明:

JCodeModel cm = new JCodeModel();
cm._class(JMod.PUBLIC | JMod.ABSTRACT, "test.TestClass", ClassType.CLASS);
cm.build(new File("."));

生成:

package test;

public abstract class TestClass {

}

JCodeModel cm = new JCodeModel();
JPackage pkg = cm._package("");
pkg._class(JMod.ABSTRACT, "TestClass2", ClassType.CLASS);
cm.build(new File("."));

生成:

public abstract class TestClass2 {

}