com.google.common.base Objects
帮助类,用来处理各种Object。 当前版本(24.1)只有以下方法,文档中的其他方法位于MoreObjects中。附在后面。
public static boolean equal(@NullableDecl Object a, @NullableDecl Object b)
定两个可能为空的对象是否相等。返回:
Object.equals(Object)
返回truepublic static int hashCode(@NullableDecl Object... objects)
用Arrays.hashCode(Object[])
方法为多个值生成哈希值。
public static <T> T firstNonNull(@NullableDecl T first, @NullableDecl T second)
返回两只值中第一个不为空的。如果两个都是null或者其他情况,返回NullPointerException。
public static ToStringHelper toStringHelper(Object self)
public static ToStringHelper toStringHelper(Class<?> clazz)
public static ToStringHelper toStringHelper(String className)
创建ToStringHelper实例。 例子:
// 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();
}