Class Objects (1.42.3)

public final class Objects

Helper functions that can operate on any Object.

Inheritance

Object > Objects

Static Methods

equal(Object a, Object b)

public static boolean equal(Object a, Object b)

Determines whether two possibly-null objects are equal. Returns:

  • 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.

Parameters
NameDescription
aObject
bObject
Returns
TypeDescription
boolean

toStringHelper(Object self)

public static Objects.ToStringHelper toStringHelper(Object self)

Creates an instance of 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();

Parameter
NameDescription
selfObject

the object to generate the string for (typically this), used only for its class name

Returns
TypeDescription
Objects.ToStringHelper