Why kotlin wrong: val minT: Long = -9223372036854775808L //Long.MIN_VALUE

Viewed 156

Kotlin's Long.MIN_VALUE == -9223372036854775808, but when I write:

val minT: Long = -9223372036854775808L //Long.MIN_VALUE

IDEA say it was wrong.

Dmitry Jemerov told me this because the - sign in Kotlin is not part of the constant but rather the unary minus operator applied to the constant value, and 9223372036854775808L is one larger than the maximum possible positive value for the Long type.

But now, why Int is right :

val minI: Int = -2147483648 //Int.MIN_VALUE

Look here:

enter image description here

1 Answers

I believe they bound like that value may need to fall within -9223372036854775808 to 9223372036854775808 because of Long.

Related