equals
Returns true if the other object is a NonPositiveInteger 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: NonPositiveInteger = NonPositiveInteger.fromInteger(value)
val y: NonPositiveInteger = NonPositiveInteger.fromInteger(value)
check(x == y)
check(x.hashCode() == y.hashCode())
val other: Integer = Integer.fromLong(-7)
val z: NonPositiveInteger = NonPositiveInteger.fromInteger(other)
check(x != z)
check(x.hashCode() != z.hashCode())Content copied to clipboard
Calling from Java
Here's an example of calling this function from Java code:
final Integer value = Integer.fromLong(-42);
final NonPositiveInteger x = NonPositiveInteger.fromInteger(value);
final NonPositiveInteger y = NonPositiveInteger.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 NonPositiveInteger z = NonPositiveInteger.fromInteger(other);
final boolean inequality =
!x.equals(z) && x.hashCode() != z.hashCode();
if (!inequality) throw new IllegalStateException("Check failed.");Content copied to clipboard