create
@ExperimentalSince(version = KotoolsTypesVersion.V4_5_0)
Creates a StrictlyNegativeInt from the specified number, which may involve rounding or truncation, or throws an IllegalArgumentException if the number is greater than or equals zero.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val isSuccess: Boolean = try {
StrictlyNegativeInt.create(-7)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)
Content copied to clipboard
The StrictlyNegativeInt type being an inline value class, this function is not available yet for Java users.
You can use the StrictlyNegativeInt.Companion.createOrNull function for returning null
instead of throwing an exception in case of invalid number.