Java中对null进行判断放在前后没有什么区别,只是为了代码规范,为了避免写代码时书写错误。下面面两个测试Demo都没有报错。null放在前面是为了避免少写一个"=","null="书写会报错,防止笔误写成"=null"时检查不出来。

 

    @Test
    public void testDemo1(){
        String str = null;
        if (str==null){
            return;
        }
    }
 
    @Test
    public void testDemo2(){
        String str = null;
        if (null==str){
            return;
        }
    }

 

相关文章:

  • 2022-02-24
  • 2022-12-23
  • 2022-01-29
  • 2022-01-25
  • 2021-12-07
  • 2021-12-07
猜你喜欢
  • 2021-12-17
  • 2021-11-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-10-12
相关资源
相似解决方案