|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.common.base.Objects
public final class Objects
Helper functions that can operate on any Object.
| Nested Class Summary | |
|---|---|
static class |
Objects.ToStringHelper
Support class for toStringHelper(java.lang.Object). |
| Method Summary | |
|---|---|
static boolean |
equal(Object a,
Object b)
Determines whether two possibly-null objects are equal. |
static int |
hashCode(Object... objects)
Generates a hash code for multiple values. |
static Objects.ToStringHelper |
toStringHelper(Object object)
Creates an instance of Objects.ToStringHelper. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean equal(@Nullable
Object a,
@Nullable
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 int hashCode(Object... objects)
Arrays.hashCode(Object[]).
This is useful for implementing Object.hashCode(). For example,
in an object that has three properties, x, y, and
z, one could write:
public int hashCode() {
return Objects.hashCode(getX(), getY(), getZ());
}
Warning: When a single object is supplied, the returned hash code
does not equal the hash code of that object.
public static Objects.ToStringHelper toStringHelper(Object object)
Objects.ToStringHelper.
This is helpful for implementing Object.toString(). For
example, in an object that contains two member variables, x,
and y, one could write:
public class ClassName {
public String toString() {
return Objects.toStringHelper(this)
.add("x", x)
.add("y", y)
.toString();
}
}
Assuming the values of x and y are 1 and 2,
this code snippet returns the string "ClassName{x=1, y=2}".
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||