Learn Kotlin: Data Types
A data type is an attribute of data which tells the compiler or interpreter what type of value the data contains. Based of the illustration variables as boxes before, we can think of the data types as color of the paper, each color can only hold one type of data (yellow for strings, blue for integers, and green for booleans).
But what are strings, integers, or booleans? They are all the basic data types that Kotlin (and most programming languages) already has.
1. Basic Data Types
In this section we describe the basic types used in Kotlin: numbers, characters, booleans, arrays, and strings.
- Numbers. Kotlin provides a set of built-in data types that represent numbers. For integer/whole numbers, there are four types with different sizes and value ranges. Kotlin provides types Float and Double for floating-point/fractional numbers.
- Characters. Represented by the data type Char for single character value.
- Booleans. Represented by the data type Boolean for one of the two possible values: true and false.
- Arrays. Represented by the Array class for group of objects.
- Strings. Represented by the data type String for group of characters (text).
2. Type inference
Type inference is a concept that allows you to omit some information — like data type — that Kotlin compiler can infer. We can ommit the data type when we declare a variable if we directly assign the intial value.
Woah! We have already covered the topics of variables and data types. Today we learned what is data types and basic data types in Kotlin. I’m happy that you make it till the end of this article, really appreciate it. As always feel free to drop a comment, and I will see you in the next one.