kqr
12/08/2025, 7:32 AMYoussef Shoaib [MOD]
12/08/2025, 7:36 AM+2 is valid Kotlin code.
The code produces a warning btw, which is good. It should be even better with the return value checker, since this whole class of "bugs" gets completely elminatedkqr
12/08/2025, 7:38 AMkqr
12/08/2025, 7:40 AMkqr
12/08/2025, 7:41 AMYoussef Shoaib [MOD]
12/08/2025, 7:42 AM-2, which is not a constant, but the unary minus operator applied to 2kqr
12/08/2025, 7:45 AMKlitos Kyriacou
12/08/2025, 9:31 AMIt's just likeThis bring some interesting behaviour. For example, the literal, which is not a constant, but the unary minus operator applied to-22
-2147483648 is of type Int, even though 2147483648 doesn't fit in an Int and is therefore of type Long. In fact, even -(<tel:2147483648|2147483648>) is of type Int. And the value Long.MIN_VALUE is -9223372036854775808 but if you try to use that as a literal you'll get a compiler error because the literal without the sign overflows Long.MAX_VALUE. In some other languages, the unary minus is taken as part of the literal itself, so this kind of behaviour doesn't arise.