createOrNull

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

Creates a NonZeroInt from the specified number, which may involve rounding or truncation, or returns null if the number equals zero.


Calling from Kotlin

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

val number: NonZeroInt? = NonZeroInt.createOrNull(23)
assertEquals(expected = "23", actual = "$number")

Calling from Java

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

final NonZeroInt number = NonZeroInt.Companion.createOrNull(23);
Assertions.assertNotNull(number);

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