Java Integer.MAX_VALUE vs Kotlin Int.MAX_VALUE

I think, this problem should be solved by Kotlin 1.3 and UInt See more here: https://kotlinlang.org/docs/reference/whatsnew13.html#unsigned-integers


This is partially answered here:

In Kotlin you need to prepend the - sign to denote negative Int which is not true in Java.

So it seems that Java will interpret hex literals as signed, whereas Kotlin will treat them as unsigned.

The negation would have to be done manually.

Small aside: JetBrains' Kotlin converter actually converts

int a = 0xffffffff;

to

var a = -0x1

but this may just be it realizing exactly what you have noticed.


The part of the spec for hexadecimal literals doesn't mention this at all, however.

Tags:

Java

Kotlin