public final class Objects extends Object
Object
.Modifier and Type | Class and Description |
---|---|
static class |
Objects.ToStringHelper
Support class for
toStringHelper(java.lang.Object) . |
Modifier and Type | Method and Description |
---|---|
static boolean |
equal(Object a,
Object b)
Determines whether two possibly-null objects are equal.
|
static Objects.ToStringHelper |
toStringHelper(Object self)
Creates an instance of
Objects.ToStringHelper . |
public static boolean equal(Object a, Object b)
true
if a
and b
are both null.
true
if a
and b
are both non-null and they are equal according to
Object.equals(Object)
.
false
in all other situations.
This assumes that any non-null objects passed to this function conform to the equals()
contract.
public static Objects.ToStringHelper toStringHelper(Object self)
Objects.ToStringHelper
.
This is helpful for implementing Object.toString()
. Specification by example:
// Returns "ClassName{}" Objects.toStringHelper(this) .toString(); // Returns "ClassName{x=1}" Objects.toStringHelper(this) .add("x", 1) .toString(); // Returns "MyObject{x=1}" Objects.toStringHelper("MyObject") .add("x", 1) .toString(); // Returns "ClassName{x=1, y=foo}" Objects.toStringHelper(this) .add("x", 1) .add("y", "foo") .toString(); // Returns "ClassName{x=1}" Objects.toStringHelper(this) .omitNullValues() .add("x", 1) .add("y", null) .toString();
self
- the object to generate the string for (typically this
), used only for its
class nameCopyright © 2011–2021 Google. All rights reserved.