create
Creates a NonZeroInt from the specified number, which may involve rounding or truncation, or throws an IllegalArgumentException if the number equals zero.
Calling from Kotlin
Here's an example of calling this method from Kotlin code:
val number: NonZeroInt = NonZeroInt.create(23)
assertEquals(expected = "23", actual = "$number")
Content copied to clipboard
Calling from Java
Here's an example of calling this method from Java code:
boolean isSuccess;
try {
NonZeroInt.Companion.create(23);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);
Content copied to clipboard
You can use the NonZeroInt.Companion.createOrNull method for returning null
instead of throwing an exception in case of invalid number.