Overview of Basic Types

Everything is an Object (on the Surface)

In Kotlin there are no separate primitive types like Java's int. You always write Int, Double, Boolean, and you can call functions on them (5.toString()). Behind the scenes the compiler still uses fast JVM primitives where it can.

TypeSizeExampleJava equivalent
Byte8 bitval b: Byte = 100byte
Short16 bitval s: Short = 2000short
Int32 bitval i = 42int
Long64 bitval l = 42Llong
Float32 bitval f = 4.5ffloat
Double64 bitval d = 4.5double
Char16 bitval c = 'K'char
Boolean-val ok = trueboolean
String-val s = "hi"String

Calling Functions on Values

Example

Even a literal number has functions.

fun main() {
    println(5.toString() + "!")
    println(3.coerceAtLeast(10))
    println(7.toDouble())
    println('a'.uppercaseChar())
    println(true.not())
    println(255.toString(2))      // 255 written in binary
}

Output

5!
10
7.0
A
false
11111111