Kotlin General Notes
Random Links
Compose Desktop/Mobile UI Skia
- https://skia.org/
- https://developer.android.com/jetpack/compose
- https://www.jetbrains.com/lp/compose/
- https://github.com/JetBrains/compose-jb/blob/master/tutorials/Getting_Started/README.md
- https://github.com/JetBrains/compose-jb/tree/master/examples/imageviewer
- https://github.com/JetBrains/compose-jb/tree/master/examples/issues
Types =====
Numbers
Byte: 8, -128..128Short: 32768 .. 32767Int: -2,147,483,648 (-231) .. 2,147,483,647 (231 - 1)Long: -9,223,372,036,854,775,808 (-263) .. 9,223,372,036,854,775,807 (263 - 1)Float: size 32Double: size 64
//val one = 1 // Intval threeBillion = 3000000000 // Longval oneLong = 1L // Longval oneByte: Byte = 1
//val pi = 3.14 // Doubleval e = 2.7182818284 // Doubleval eFloat = 2.7182818284f // Float, actual value is 2.7182817
//fun main() { fun printDouble(d: Double) { print(d) }
val i = 1 val d = 1.1 val f = 1.1f
printDouble(d) // printDouble(i) // Error: Type mismatch // printDouble(f) // Error: Type mismatch}
// Underscores in numeric literalsval oneMillion = 1_000_000val creditCardNumber = 1234_5678_9012_3456Lval socialSecurityNumber = 999_99_9999Lval hexBytes = 0xFF_EC_DE_5Eval bytes = 0b11010010_01101001_10010100_10010010
// Hypothetical code, does not actually compile:val a: Int? = 1 // A boxed Int (java.lang.Integer)val b: Long? = a // implicit conversion yields a boxed Long (java.lang.Long)print(b == a) // Surprise! This prints "false" as Long's equals() checks whether the other is Long as wellLiteral constants
- Decimals:
123, Longs tagged withL - Hexadecimals:
Ox0F - Binaries:
0b000001011 - Octal: Not supported
- Doubles by default:
123.5, 123.5e10
Explicit conversions
- toByte():
Byte - toInt():
Int - toLong():
Long - toFloat:
Float - toDouble:
Double - toChar():
Char
val l = 1L + 3 // Long + Int => LongCharacters
Charcannot be treated as a number.- Character literals go in single quotes: ‘1’
- Supported escape sequences:
\t,\b,\n,\r,\',\",\\and\$
fun check(c: Char) { if (c == 1) { // ERROR: incompatible types // ... }}Booleans
- two values:
trueandfalse ||– lazy disjunction&&– lazy conjunction!- negation
Array
- Array has get/set access that is implemented by
[] - Array has
sizefor length.