Utku
Utku

Reputation: 2177

Cannot create abstract class in codemodel?

My code:

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

no matter what I write to mods or ClassType parameter, the outcome is always a public class.

How can I create an abstract class?

Upvotes: 1

Views: 113

Answers (1)

John Ericksen
John Ericksen

Reputation: 11113

Strange. It seems JCodeModel doesn't create abstract classes without a package. The following cases have a package declaration:

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

Generates:

package test;

public abstract class TestClass {

}

or

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

Generates:

public abstract class TestClass2 {

}

Upvotes: 1

Related Questions