JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
Kotlin
Kotlin Documenation
More
Share
Explore
Kotlin Documenation
Variables and Data Types
Kotlin has two types of variables:
val
and
var
.
val
: Immutable variable. Once assigned, cannot be reassigned.
var
: Mutable variable. Can be reassigned.
val
name
:
String
=
"Kotlin"
// name = "C#" (This is an error, can't be reassigned)
var
age
:
Int
=
10
// age = 12 (This is allowed)
// var or val init variable with out assigning the data is error
val
userName
:
String
// it's an error since there is no data assigned
Data Types
Kotlin is statically typed, meaning the type of a variable is known at compile time.
Integers
Byte
,
Short
,
Int
,
Long
Unsigned integers
UByte
,
UShort
,
UInt
,
ULong
Floating-point numbers
Float
,
Double
Booleans
Boolean
Characters
Char
Strings
String
Examples:
val
integer
:
Int
=
10
val
longNumber
:
Long
=
100L
val
doubleNumber
:
Double
=
10.5
val
floatNumber
:
Float
=
10.5F
val
booleanValue
:
Boolean
=
true
val
charValue
:
Char
=
'A'
val
stringValue
:
String
=
"Hello"
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.