11.3 The java.util.Objects Utility Class
The Objects class contains some static utility functions. These functions primarily perform null tests to avoid a subsequent NullPointerException when object methods are called.
11.3.1 Built-In Null Tests for equals(...)/hashCode()
For example, if the object variable name of a person is null, then name.hashCode() can’t simply be called without a NullPointerException following the call. Three methods of Objects perform null tests before being passed to the Object method: equals(…), hashCode(), and toString(). An additional helper method works with comparators, which you’ll learn more about in Section 11.4 .
class java.util. Objects
-
static boolean equals(Object a, Object b)Returns true if both ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access