equals

operator override fun equals(other: Any?): Boolean

Returns true if the other object is a NonNegativeInteger representing the same numeric value as this one, or returns false otherwise.

This function follows the contract of Any.equals.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val value: Integer = Integer.fromLong(42)
val x: NonNegativeInteger = NonNegativeInteger.fromInteger(value)
val y: NonNegativeInteger = NonNegativeInteger.fromInteger(value)
check(x == y)
check(x.hashCode() == y.hashCode())

val other: Integer = Integer.fromLong(7)
val z: NonNegativeInteger = NonNegativeInteger.fromInteger(other)
check(x != z)
check(x.hashCode() != z.hashCode())

Calling from Java

Here's an example of calling this function from Java code:

final Integer value = Integer.fromLong(42);
final NonNegativeInteger x = NonNegativeInteger.fromInteger(value);
final NonNegativeInteger y = NonNegativeInteger.fromInteger(value);
final boolean equality = x.equals(y) && x.hashCode() == y.hashCode();
if (!equality) throw new IllegalStateException("Check failed.");

final Integer other = Integer.fromLong(7);
final NonNegativeInteger z = NonNegativeInteger.fromInteger(other);
final boolean inequality =
!x.equals(z) && x.hashCode() != z.hashCode();
if (!inequality) throw new IllegalStateException("Check failed.");