官术网_书友最值得收藏!

Basic types in Kotlin

One of the big changes in Kotlin from Java is that, in Kotlin, everything is an object. If you come from a Java background, then you will already be aware that in Java there are special primitive types that are treated differently from objects. They cannot be used as generic types, do not support method/function calls, and cannot be assigned null. An example is the boolean primitive type.

Java introduced wrapper objects to offer a workaround in which primitive types are wrapped in objects, so that java.lang.Boolean wraps a boolean primitive type in order to smooth over the distinctions. Kotlin removes this necessity entirely from the language by promoting the primitives to full objects.

Whenever possible, the Kotlin compiler will map basic types back to JVM primitives for performance reasons. However, sometimes the values must be boxed, such as when the type is nullable, or when it is used in generics. Boxing is the conversion from a primitive type to a wrapper type, which takes place whenever an object is required but a primitive is presented.

Two different values that are boxed might not use the same instance, so referential equality is not guaranteed on boxed values.
主站蜘蛛池模板: 大同县| 广德县| 保亭| 汽车| 华坪县| 栖霞市| 新民市| 长阳| 福安市| 麻栗坡县| 利津县| 蓬安县| 阳城县| 黄山市| 营山县| 吴忠市| 汉沽区| 唐海县| 赫章县| 蒲江县| 岑巩县| 海城市| 凌云县| 上饶县| 海伦市| 安阳县| 治县。| 木里| 额尔古纳市| 临城县| 平和县| 买车| 普兰县| 师宗县| 巴中市| 盐边县| 来凤县| 南澳县| 宜宾市| 余干县| 石嘴山市|