为什么我不建议你用去 “ ! = null " 做判空?
往期热门文章:
4、爽啊!Intellij IDEA 神器居然还藏着这些实用小技巧 !
作者:lizeyang 来源:blog.csdn.net/lizeyang/article/details/40040817
...if (someobject != null) {
    someobject.doCalc();}...public interface Action {
  void doSomething();}
 
public interface Parser {
  Action findAction(String userInput);}public class MyParser implements Parser {
  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;
    }
  }}Parser parser = ParserFactory.getParser();
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();}ParserFactory.getParser().findAction(someInput).doSomething();
"bar".equals(foo) 
foo.equals("bar")往期热门文章: 
1、《历史文章分类导读列表!精选优秀博文都在这里了!》 
2、万亿级数据应该怎么迁移? 3、从应用到底层 36张图带你进入Redis世界 4、写代码有这16个好习惯,可以减少80%非业务的bug 5、顺丰快递:请签收MySQL灵魂十连 
6、一个基于SpringBoot + MyBatis + Vue的代码生成器 7、Redis 分布式锁使用不当,超卖了100瓶飞天茅台!!! 8、如何设计订单系统?这篇写得太好了! 9、如果MySQL磁盘满了,会发生什么?还真被我遇到了! 10、阿里开源的27个项目,值得收藏! 
评论
