public final class MoreObjects extends Object
Object, and are not already provided in
Objects.
See the Guava User Guide on writing
Object methods with MoreObjects.
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 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{}"
MoreObjects.toStringHelper(this)
.toString();
<p>
// Returns "ClassName{x=1}"
MoreObjects.toStringHelper(this)
.add("x", 1)
.toString();
<p>
// Returns "MyObject{x=1}"
MoreObjects.toStringHelper("MyObject")
.add("x", 1)
.toString();
<p>
// Returns "ClassName{x=1, y=foo}"
MoreObjects.toStringHelper(this)
.add("x", 1)
.add("y", "foo")
.toString();
<p>
// Returns "ClassName{x=1}"
MoreObjects.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 nameObjects.toStringHelper().Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.