fromIntegerOrNull
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 value: Integer = Integer.fromLong(-42)
val result: NonPositiveInteger = NonPositiveInteger.fromInteger(value)
check(result.toInteger() == value)
val positive: Integer = Integer.fromLong(1)
val exception: Throwable? = runCatching {
NonPositiveInteger.fromInteger(positive)
}.exceptionOrNull()
check(exception is IllegalArgumentException)
val safeResult: NonPositiveInteger? =
NonPositiveInteger.fromIntegerOrNull(positive)
check(safeResult == null)Content copied to clipboard
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 is positive.