https://kotlinlang.org logo
Title
f

Florian

06/13/2019, 11:28 AM
why do I not need an L suffix in Kotlin to create a Long literal
p

Pavlo Liapota

06/13/2019, 2:09 PM
Because otherwise it is
Int
literal 🙂
f

Florian

06/13/2019, 2:09 PM
But it is not needed
unlike in Java
p

Pavlo Liapota

06/13/2019, 2:12 PM
Kotlin does not have implicit cast of primitive types.
s

Shawn

06/13/2019, 2:55 PM
fun longConsumer(long: Long) {
    println(long)
}

longConsumer(42)
works in a scratch file ¯\_(ツ)_/¯
f

Florian

06/13/2019, 6:58 PM
When you assign a large number to a variable it infers it as Long without the L
I am wondering why
b

bdawg.io

06/15/2019, 5:00 AM
It's all about the compiler being able to infer what you want.
f

Florian

06/15/2019, 9:03 AM
right, but in Java a number literal without an L is an int
even if its out of range of int
b

bdawg.io

06/15/2019, 2:26 PM
Well Kotlin isn't Java :) if you leave a numeric literal ambiguous and the compiler determines that int and long are both acceptable, I really like that it will use a long. Otherwise, what's the point in me having such a large literal in my code if it's just going to get overflowed anyways
f

Florian

06/15/2019, 7:00 PM
yea it makes sense
But why did they add that in Java in the first place
b

bdawg.io

06/16/2019, 6:58 AM
Java was generally verbose and explicit, so inferring what you probably meant to do wasn't really a thing.
f

Florian

06/16/2019, 9:50 AM
Ok thank you