https://kotlinlang.org logo
#announcements
Title
# announcements
e

egorand

06/21/2019, 2:28 PM
are Kotlin’s primitive type ranges different from Java ones? I’ve got this Java code that compiles just fine:
Copy code
public static final Long DEFAULT_DEFAULT_SINT64 = -9223372036854775808L;
and a similar piece of Kotlin code that fails with “value out of range”:
Copy code
const val DEFAULT_DEFAULT_SINT64: Long = -9223372036854775808L
to make matters worse, I’m producing this value using
BigInteger(value).toLong()
, which is supposed to narrow an out of range value, but apparently it doesn’t work with Kotlin
y

yawkat

06/21/2019, 2:32 PM
the primitive ranges are the same, 9223372036854775808L just isnt a valid long - in java, the - is considered first, but in kotlin, the positive value must also be in range. you can fix this by just doing - 1, or using Long.MIN_VALUE
e

egorand

06/21/2019, 2:33 PM
got it, that makes sense! thank you
2 Views