create

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

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


Calling from Kotlin

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

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

Calling from Java

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

boolean isSuccess;
try {
NegativeInt.Companion.create(-7);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);

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