variables - TonyGuyot/kotlin-notes GitHub Wiki
Variables and types
Defining variables
val a: Int = 1<- define type and valueval a = 1<- shorter version, type is inferred from valuevar a: Int<- type only, value must be set later
There are two keywords to define a variable:
valfor read-only variables (re-assignment of value is prohibited)varfor a mutable variable
Basic types
| keyword | description |
|---|---|
Byte |
8-bit integer |
Short |
16-bit integer |
Int |
32-bit integer |
Long |
64-bit integer |
Float |
32-bit floating point number |
Double |
64-bit floating point number |
Char |
single character |
Boolean |
16-bit integer |
String |
character string (immutable) |