build.gradle(模块):
productFlavors {
mytest {
...
buildConfigField "boolean", "SHORT_ENUM", "false"
}
mysecondtest {
buildConfigField "boolean", "SHORT_ENUM", "true"
}
在 MyClass 中,我想根据我定义的 buildConfigField 在构建期间定义枚举成员:
public class MyClass {
// members initialization
public enum MYENUM {
if (BuildConfig.SHORT_ENUM) {
FIRST(0),
SECOND(1);
}
else { // SHORT_ENUM is false
FIRST(0),
SECOND(1),
THIRD(2),
FORTH(3);
}
private int value;
MYENUM(int v) {
value = v;
}
}
....
}
但它不起作用。有可能做我想做的事吗?如果是,那么如何?