I noticed, one interesting thing.
Java's Integer.MAX_VALUE
is 0x7fffffff
(2147483647)
Kotlin's Int.MAX_VALUE
is 2147483647
but if you write
in Java:
int value = 0xFFFFFFFF;
//everything is fine (but printed value is '-1')
in Kotlin:
val value: Int = 0xFFFFFFFF //You get exception
The integer literal does not conform to the expected type Int
Interesting right? So you're able to do something like new java.awt.Color(0xFFFFFFFF, true)
in Java but not in Kotlin.
Color
类在"二进制"级别上使用该int,因此所有构造函数(Color(int rgba)
或Color(int r, int g, int b, int a)
)在两个平台上都工作得很好.
我为Kotlin 找到的唯一变通办法是java.awt.Color(0xFFFFFFFF.toInt(), true)
.
Any idea why is it like this in Kotlin?