In kotlin : val a = 10 val b = 10 And in java : in...
# getting-started
h
In kotlin : val a = 10 val b = 10 And in java : int x = 10 int y = 10 What’s the difference?
e
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
oh my bad , i have to type var but here i am talking more about memory allocation
e
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
Thanks