hashCode
Returns a hash code value for this integer.
This function follows the contract of Any.hashCode, with an additional property: if two instances of NonZeroInteger are not equal, then calling this function on these objects must produce different hash codes.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val x: NonZeroInteger = NonZeroInteger.fromLong(42)
val y: NonZeroInteger = NonZeroInteger.parse("+00042")
check(x == y)
check(x.hashCode() == y.hashCode())
val z: NonZeroInteger = NonZeroInteger.fromLong(-42)
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 NonZeroInteger x = NonZeroInteger.fromLong(42L);
final NonZeroInteger y = NonZeroInteger.parse("+00042");
final boolean equality = x.equals(y) && x.hashCode() == y.hashCode();
if (!equality) throw new IllegalStateException("Check failed.");
final NonZeroInteger z = NonZeroInteger.fromLong(-42L);
final boolean inequality =
!x.equals(z) && x.hashCode() != z.hashCode();
if (!inequality) throw new IllegalStateException("Check failed.");Content copied to clipboard