我正在编写代码if并else if找到某种类型并从中创建相应的值。我想知道如何提高效率,我在论坛中找到了以下帖子,但我没有类似的类型boolean,我的类型是bollean.edm等char.edm。
有没有办法使用以下代码进行调整以支持我的情况?
public static void main(String[] args) throws InterruptedException {
String typeName = "Boolean";
String memberValue = "memberValue";
SwitchInputType type = Type.valueOf(typeName).makeType(memberValue);
}
enum Type {
Boolean {
SwitchInputType makeType(String memberValue) {
return new SwitchInputType<Boolean>(new Boolean(memberValue));
}
},
Double {
SwitchInputType makeType(String memberValue) {
return new SwitchInputType<Double>(new Double(memberValue));
}
},
Int32 {
SwitchInputType makeType(String memberValue) {
return new SwitchInputType<Integer>(new Integer(memberValue));
}
};
// All must do this.
abstract SwitchInputType makeType(String memberValue);
}
static class SwitchInputType<T> {
public SwitchInputType(Object o) {
}
}