I studied the Objects.java methods, but I could not find too many useful aspects of these methods. For example, the code that will work when I use Objects.isNull:
public static boolean isNull(Object obj) { return obj == null; }
There are two ways to check the invalidity of two objects:
if(o == null) if(Objects.isNull(o))
Thus, there are not many differences between them. Another example of code that will work, I use Objects.toString
public static String toString(Object o) { return String.valueOf(o); }
When I use it, it calls the object's toString in the background (with only one difference, it writes "null" if the object is null because it uses String.valueOf ()
And Objects.equals:
public static boolean equals(Object a, Object b) { return (a == b) || (a != null && a.equals(b)); }
It will check for zero in each check (not knowing whether it is necessary or not.)
Am I mistaken? If I, why should I use these methods and other methods of the Object.java object?
EDIT
I did not ask this question only for Objects.isNull and Objects.nonNull, I want to know the purpose, usability (except lambdas) and the advantages of the Objects class and its methods. But in javadoc it is written that only for Objects.isNull and Objects.nonNull there is a goal to use with lambdas (as a filter of predicates (Objects :: isNull)). I want to know others .
source share