Kotlin automatically forces us to use wrappers like Float, Double, Int, Boolean, etc.
But sometimes, for performance and memory reasons, we need to use primitive types.
I am aware that this can be done if you use special arrays such as IntArray, DoubleArray, FloatArray, etc.
But what about single primitives in a variable?
Kotlin doesn't use wrapper types for non-nullable types, such as Int
or Float
- those will get compiled into int
and float
. However, if you use nullable types, such as Int?
or Float?
, Kotlin will use wrapper types - Integer
and Float
- to be able to represent null values. Using non-nullable primitive types in Kotlin will not lead to unnecessary allocations.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.