java.util.Objects.isNull vs object == null

前端 未结 5 1252
盖世英雄少女心
盖世英雄少女心 2020-12-08 03:57

As you know, java.util.Objects is

This class consists of static utility methods for operating on objects.

One of such methods i

5条回答
  •  無奈伤痛
    2020-12-08 04:15

    should use object == null over Objects.isNull() in a if statement?

    If you look at the source code of IsNull method,

     /* Returns true if the provided reference is null otherwise returns false.*/
    
     public static boolean isNull(Object obj) {
         return obj == null;
     }
    

    It is the same. There is no difference. So you can use it safely.

提交回复
热议问题