I have tried using Int and Integer types in Kotlin.Although I don\'t see any difference. Is there a difference between Int and Integer types in Kotlin?Or are they the same?
Just have a look at https://kotlinlang.org/docs/reference/basic-types.html#representation
On the Java platform, numbers are physically stored as JVM primitive types, unless we need a nullable number reference (e.g. Int?) or generics are involved. In the latter cases numbers are boxed.
That means, that Int
is represented as primitive int
. Only in cases when nullability or generics are involved, the backing Wrapper Type Integer
must be used.
If you use Integer
from the beginning, you always work with the wrapper type and never with the primitive int
.