why do I not need an L suffix in Kotlin to create ...
# codingconventions
f
why do I not need an L suffix in Kotlin to create a Long literal
p
Because otherwise it is
Int
literal 🙂
f
But it is not needed
unlike in Java
p
Kotlin does not have implicit cast of primitive types.
s
Copy code
fun longConsumer(long: Long) {
    println(long)
}

longConsumer(42)
works in a scratch file ¯\_(ツ)_/¯
f
When you assign a large number to a variable it infers it as Long without the L
I am wondering why
b
It's all about the compiler being able to infer what you want.
f
right, but in Java a number literal without an L is an int
even if its out of range of int
b
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
yea it makes sense
But why did they add that in Java in the first place
b
Java was generally verbose and explicit, so inferring what you probably meant to do wasn't really a thing.
f
Ok thank you