createOrNull

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

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


Calling from Kotlin

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

val number: StrictlyNegativeInt? = StrictlyNegativeInt.createOrNull(-7)
assertNotNull(number)

The StrictlyNegativeInt type being an inline value class, this function is not available yet for Java users.

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