fromIntegerOrNull

Returns a NonZeroInteger representing the specified value, or returns null if value represents zero.


Calling from Kotlin

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

val value: Integer = Integer.fromLong(42)
val result: NonZeroInteger = NonZeroInteger.fromInteger(value)
check("$result" == "42")

val zero: Integer = Integer.fromLong(0)
val exception: Throwable? =
runCatching { NonZeroInteger.fromInteger(zero) }.exceptionOrNull()
check(exception is IllegalArgumentException)

val safeResult: NonZeroInteger? =
NonZeroInteger.fromIntegerOrNull(zero)
check(safeResult == null)

This function is hidden from Java, because nullability is not explicit in its type system.

See the fromInteger function for throwing an exception instead of returning null when value represents zero.