createOrNull
Creates a StrictlyNegativeDouble 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: Number = Random.nextInt(Int.MIN_VALUE until 0)
val actual: StrictlyNegativeDouble? =
StrictlyNegativeDouble.createOrNull(number)
assertNotNull(actual)
Content copied to clipboard
Calling from Java
Here's an example of calling this function from Java code:
final Random random = new Random();
final Number number = random.nextInt(Integer.MIN_VALUE, 0);
final StrictlyNegativeDouble actual =
StrictlyNegativeDouble.Companion.createOrNull(number);
Assertions.assertNotNull(actual);
Content copied to clipboard
You can use the StrictlyNegativeDouble.Companion.create function for throwing an exception instead of returning null
in case of invalid number.