其他
拒绝 ! = null ,大神有更好的方法!
someobject.doCalc();}...
void doSomething();}
public interface Parser {
Action findAction(String userInput);}
private static Action DO_NOTHING = new Action() {
public void doSomething() { /* do nothing */ }
};
public Action findAction(String userInput) {
// ...
if ( /* we can't find any actions */ ) {
return DO_NOTHING;
}
}}
if (parser == null) {
// now what?
// this would be an example of where null isn't (or shouldn't be) a valid response
}
Action action = parser.findAction(someInput);
if (action == null) {
// do nothing} else {
action.doSomething();}
SpringBoot+Vue 完整的外卖系统,手机端和后台管理,附源码!
带工作流的SpringBoot后台管理项目,一个企业级快速开发解决方案