2
我想用Sun的codemodel創建一個類似於下面的代碼片段枚舉類孫CodeModel - 如何使用多個參數創建枚舉
public enum REPORT_COLUMNS {
MONTH("month", true, false),
DAY("day", false, true);
private final String column;
private final boolean filterable;
private final boolean includeInHavingClause;
private REPORT_COLUMNS(String column, boolean filterable, boolean includeInHavingClause) {
this.column = column;
this.filterable = filterable;
this.includeInHavingClause = includeInHavingClause;
}
public String getColumn() {
return column;
}
public boolean isFilterable() {
return filterable;
}
public boolean includeInHavingClause() {
return includeInHavingClause;
}
}
我能夠生成枚舉的構造函數,字段代碼, getter方法。但是,我無法用三個值初始化枚舉常量。 JDefinedClass有一個方法enumConstant,它只接受枚舉常量的名稱作爲參數。我已經通讀了JEnumConstant類的文檔,但是找不到任何會向枚舉常量添加三個值的內容。
它完美地工作。非常感謝Jan Galinski! – Anand
更新的github網址:https://github.com/jangalinski/stackoverflow-jangalinski/blob/master/src/test/java/com/github/jangalinski/codemodel/GenerateEnumTest.java – user1050755