Objects

object Objects
class Object
trait Matchable
class Any
Objects.type

Type members

Classlikes

Compare Builder

Compare Builder

Since:

4.2.4

Equals Builder

Equals Builder

Since:

3.1.0

class ToStringBuilder(val className: String)

Support class for Objects.toStringBuilder.

Support class for Objects.toStringBuilder.

Value members

Concrete methods

@inline
def default[T](clazz: Class[T]): T
def defaultIfNull[T](value: T, defaultValue: T): T

Returns a default value if the object passed is null.

Returns a default value if the object passed is null.

defaultIfNull(null, null)      = null
defaultIfNull(null, "")        = ""
defaultIfNull(null, "zz")      = "zz"
defaultIfNull("abc", *)        = "abc"
defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
Value parameters:
<

T> the type of the object

defaultValue

the default value to return, may be null

object

the Object to test, may be null

Returns:

object if it is not null, defaultValue otherwise

Since:

3.0

@inline
def equals(a: Any, b: Any): Boolean

Compares two objects for equality, where either one or both objects may be null.

Compares two objects for equality, where either one or both objects may be null.

equals(null, null)                  = true
equals(null, "")                    = false
equals("", null)                    = false
equals("", "")                      = true
equals(Boolean.TRUE, null)          = false
equals(Boolean.TRUE, "true")        = false
equals(Boolean.TRUE, Boolean.TRUE)  = true
equals(Boolean.TRUE, Boolean.FALSE) = false
Value parameters:
a

the first object, may be null

b

the second object, may be null

Returns:

true if the values of both objects are the same

Since:

3.0

def equals(a: Array[Any], b: Array[Any]): Boolean

Compares two object array for equality, where either one or both objects may be null. Note: Don't user Any[_],fo after type erase ,it has same signature with equals(a:Any,b:Any)

Compares two object array for equality, where either one or both objects may be null. Note: Don't user Any[_],fo after type erase ,it has same signature with equals(a:Any,b:Any)

def getIdentityHexString(obj: AnyRef): String

Return a hex String form of an object's identity hash code.

Return a hex String form of an object's identity hash code.

Value parameters:
obj

the object

Returns:

the object's identity code in hex notation

def toString(obj: AnyRef): String

Gets the toString of an Object returning an empty string ("") if null input.

Gets the toString of an Object returning an empty string ("") if null input.

toString(null)         = ""
toString("")           = ""
toString("bat")        = "bat"
toString(Boolean.TRUE) = "true"
Value parameters:
obj

the Object to toString, may be null

Returns:

the passed in Object's toString, or nullStr if null input

See also:

String#valueOf(Object)

Since:

3.0

def toStringBuilder(self: AnyRef): ToStringBuilder

Creates an instance of [[ToStringBuilder]].

Creates an instance of [[ToStringBuilder]].

This is helpful for implementing Object#toString(). Specification by example:

 // Returns "ClassName{}"
 Objects.toStringBuilder(this)
     .toString();

 // Returns "ClassName{x=1}"
 Objects.toStringBuilder(this)
     .add("x", 1)
     .toString();

 // Returns "MyObject{x=1}"
 Objects.toStringBuilder("MyObject")
     .add("x", 1)
     .toString();

 // Returns "ClassName{x=1, y=foo}"
 Objects.toStringBuilder(this)
     .add("x", 1)
     .add("y", "foo")
     .toString();
 }}

 // Returns "ClassName{x=1}"
 Objects.toStringBuilder(this)
     .omitNullValues()
     .add("x", 1)
     .add("y", null)
     .toString();
Value parameters:
self

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

Since:

3.1

def toStringBuilder(clazz: Class[_]): ToStringBuilder

Creates an instance of ToStringBuilder in the same manner as toStringBuilder(AnyRef), but using the name of clazz instead of using an instance's Object#getClass().

Creates an instance of ToStringBuilder in the same manner as toStringBuilder(AnyRef), but using the name of clazz instead of using an instance's Object#getClass().

Value parameters:
clazz

the Class of the instance

def toStringBuilder(className: String): ToStringBuilder

Creates an instance of ToStringBuilder in the same manner as toStringBuilder(AnyRef), but using className instead of using an class instance.

Creates an instance of ToStringBuilder in the same manner as toStringBuilder(AnyRef), but using className instead of using an class instance.

Value parameters:
className

the name of the instance type