create
Creates a StrictlyNegativeDouble 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 result: Result<StrictlyNegativeDouble> = runCatching {
StrictlyNegativeDouble.create(-23)
}
println(result.isSuccess) // true
Content copied to clipboard
Calling from Java
Here's an example of calling this function from Java code:
// The following code prints 'Success'.
try {
StrictlyNegativeDouble.Companion.create(-23);
System.out.println("Success");
} catch (IllegalArgumentException exception) {
final String reason = exception.getMessage();
System.out.println("Failure: " + reason);
}
Content copied to clipboard
You can use the StrictlyNegativeDouble.Companion.createOrNull for returning null
instead of throwing an exception in case of invalid number.