unaryMinus

operator fun unaryMinus(): Integer

Returns the negative of this integer.


Calling from Kotlin

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

val x: Integer = Integer.parse("99999999999999999999")
val result: Integer = -x
val expected: Integer = Integer.parse("-99999999999999999999")
check(result == expected)

Calling from Java

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

final Integer x = Integer.parse("99999999999999999999");
final Integer result = x.unaryMinus();
final Integer expected = Integer.parse("-99999999999999999999");
final boolean check = result.equals(expected);
if (!check) throw new IllegalStateException("Check failed.");