public enum ProcessorFactory {
A("ap") {
Processor create() throws Exception {
return new AProcessor();
}
},
B("bp"){
Processor create() throws Exception {
return new BProcessor();
}
};
abstract Processor create() throws Exception;
public static Processor getProcessor(String product) throws Exception {
ProcessorFactory factory = valueOf(product);
return factory.create();
}
private String product;
private ProcessorFactory(String product) {
this.product = product;
}
}
现在当我尝试打电话时
ProcessorFactory.getProcessor("ap");
它抛出上述异常。有任何想法吗?