https://kotlinlang.org logo
#getting-started
Title
# getting-started
h

Hassaan

05/07/2022, 3:44 AM
In kotlin : val a = 10 val b = 10 And in java : int x = 10 int y = 10 What’s the difference?
e

ephemient

05/07/2022, 3:55 AM
the only difference in this example is that
val
is not re-assignable
while Kotlin has only a single
Int
type conceptually, the compiler will represent it with a boxed Integer or primitive int as appropriate, automatically
h

Hassaan

05/07/2022, 3:59 AM
oh my bad , i have to type var but here i am talking more about memory allocation
e

ephemient

05/07/2022, 3:59 AM
there is no difference in memory allocation
a
<http://kotlin.Int|kotlin.Int>
is never a mutable box. on JVM, it is represented by either a primitive
int
wherever possible, or an immutable boxed
java.lang.Integer
where not
you should consider
Int
to be like other value types: they have no identity, so instances (and whether they're the same or not) aren't even part of the language model
h

Hassaan

05/07/2022, 4:05 AM
Thanks
2 Views