October 2018
Intermediate to advanced
370 pages
9h 15m
English
In Kotlin, we can also declare a specific type of variable with var variableName : nameOfDataType type annotation:
var myInteger : Intvar myString : Stringval myDouble : Double
Once the variables are declared, we can assign values to them:
myInteger = 10myString = "Hello"myDouble = 12.123
Having variable declarations with explicit data types and assigning a value at the same time is also possible:
val myInt : Int = 10var myString : String = "Hello"
Variable declaration and initialization is explained in the following example:
fun main(args: Array<String>) { var myName: String // Variables can be initialized explicitly myName = "Jon" // Initialization // declaration and initialization in one line var myInt: Int = 10 var myLong: ...
Read now
Unlock full access