fromLongOrNull
Returns a NonZeroInteger representing the specified value, or returns null if value is 0.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val result: NonZeroInteger = NonZeroInteger.fromLong(42)
check("$result" == "42")
val exception: Throwable? =
runCatching { NonZeroInteger.fromLong(0) }.exceptionOrNull()
check(exception is IllegalArgumentException)
val safeResult: NonZeroInteger? = NonZeroInteger.fromLongOrNull(0)
check(safeResult == null)Content copied to clipboard
This function is hidden from Java, because nullability is not explicit in its type system.
See the fromLong function for throwing an exception instead of returning null when value is 0.