public class Welcome {
public class OperationFactory {
public static Operation createOperate(String operate) {
Operation operation = null;
if("+".equalsIgnoreCase(operate)) {
operation = new OperationAdd();
}else if("-".equalsIgnoreCase(operate)) {
operation = new OperationSub();
}else if("*".equalsIgnoreCase(operate)) {
operation = new OperationMul();
}else {
operation = new OperationDiv();
}
return operation;
}
}
}
问题是:方法createOperate不能声明为static;静态方法只能在静态或顶级类型中声明 我不知道该如何解决。谢谢
答案 0 :(得分:1)
正如错误消息明确指出的那样,您有3个选项:
createOperate
方法更改为非静态OperationFactory
类更改为静态createOperate
移至封闭的Welcome
类