先看枚举类:
public enum Algorithm {
A1(100.0,"A001.01"),A2(0.9,"A001.02");
double desc;
String value;
private Algorithm(double desc, String value){
this.desc = desc;
this.value = value;
}
public double getDesc() {
return desc;
}
public void setDesc(double desc) {
this.desc = desc;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public static double getValue(String value) {
Algorithm[] vals = Algorithm.values();
for (Algorithm val : vals) {
if(value == val.getValue()){
return val.getDesc();
}
}
return 0.0d;
}
public static void main(String[] args) {
System.out.println(Algorithm.getValue("A001.01"));
System.out.println(Algorithm.getValue("A001.02"));
}
}
再看runAsDouble:
@Override
public double runAsDouble() {
try {
LOGGER.error("------runAsDouble-----");
LOGGER.error("------ Algorithm.getValue-----");
// threshold = Algorithm.getValue(algorithm);//这个值为什么拿不到?
觉得好奇怪,我用其他办法解决了。