public final class MoreObjects extends Object
Object.
See the Guava User Guide on writing
Object methods with Objects.
Imported from com.google.guava:17.0 Objects
| Modifier and Type | Class and Description |
|---|---|
static class |
MoreObjects.ToStringHelper
Support class for
toStringHelper(java.lang.Object). |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
firstNonNull(T first,
T second)
Returns the first of two given parameters that is not
null, if
either is, or otherwise throws a NullPointerException. |
static MoreObjects.ToStringHelper |
toStringHelper(Object self)
Creates an instance of
MoreObjects.ToStringHelper. |
public static MoreObjects.ToStringHelper toStringHelper(Object self)
MoreObjects.ToStringHelper.
This is helpful for implementing Object.toString().
Specification by example:
// Returns "ClassName{}"
Objects.toStringHelper(this)
.toString();
<p>
// Returns "ClassName{x=1}"
Objects.toStringHelper(this)
.add("x", 1)
.toString();
<p>
// Returns "MyObject{x=1}"
Objects.toStringHelper("MyObject")
.add("x", 1)
.toString();
<p>
// Returns "ClassName{x=1, y=foo}"
Objects.toStringHelper(this)
.add("x", 1)
.add("y", "foo")
.toString();
<p>
// Returns "ClassName{x=1}"
Objects.toStringHelper(this)
.omitNullValues()
.add("x", 1)
.add("y", null)
.toString();
}
Note that in GWT, class names are often obfuscated.
self - the object to generate the string for (typically this),
used only for its class namepublic static <T> T firstNonNull(T first,
T second)
null, if
either is, or otherwise throws a NullPointerException.first if first is not null, or
second if first is null and second is
not nullNullPointerException - if both first and second were
nullCopyright © 2018. All Rights Reserved.