are Kotlin’s primitive type ranges different from ...
# announcements
e
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
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
got it, that makes sense! thank you