createOrNull

@ExperimentalSince(version = KotoolsTypesVersion.V4_5_0)
fun createOrNull(number: Number): NegativeInt?

Creates a NegativeInt from the specified number, which may involve rounding or truncation, or returns null if the number is greater than zero.


Calling from Kotlin

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

val number: NegativeInt? = NegativeInt.createOrNull(-7)
assertEquals(expected = "-7", actual = "$number")

Calling from Java

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

final NegativeInt number = NegativeInt.Companion.createOrNull(-7);
Assertions.assertNotNull(number);

You can use the NegativeInt.Companion.create function for throwing an exception instead of returning null in case of invalid number.