This chapter covers
- Primitive and other basic types and their correspondence to the Java types
- Kotlin collections, arrays, and their nullability and interoperability stories
Beyond its support for nullability, Kotlin’s type system has several essential features to improve the reliability of your code, and implements many lessons learned from other typesystems, including Java’s. These decisions shape the way you work with everything in Kotlin code, from primitive values and basic types to the hierarchy of collections found in the Kotlin standard library. Kotlin introduces features that aren’t present in other type sytems, such as read-only collections, and refines or doesn’t expose parts of the type system that have turned out to be problematic or unnecessary, such as first-class support for arrays. Let’s take a closer look, starting with the basic building blocks.
This section describes the basic types used in programs, such as Int
, Boolean
, and Any
. Unlike Java, Kotlin doesn’t differentiate primitive types and wrappers. You’ll shortly learn why, and how it works under the hood. You’ll see the correspondence between Kotlin types and such Java types as Object
and Void
, as well.