fromLongOrNull

Returns a NonPositiveInteger representing the specified value, or returns null if value is positive.


Calling from Kotlin

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

val result: NonPositiveInteger = NonPositiveInteger.fromLong(-42)
check(result.toInteger() == Integer.fromLong(-42))

val exception: Throwable? =
runCatching { NonPositiveInteger.fromLong(1) }.exceptionOrNull()
check(exception is IllegalArgumentException)

val safeResult: NonPositiveInteger? =
NonPositiveInteger.fromLongOrNull(1)
check(safeResult == null)

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 positive.