August 2017
Intermediate to advanced
440 pages
10h
English
As we saw in previous examples, unlike Java, the Kotlin type is defined after the variable name:
var title: String
At first glance, this may look strange to Java developers, but this construct is a building block of a very important feature of Kotlin called type inference. Type inference means that the compiler can infer type from context (the value of an expression assigned to a variable). When variable declaration and initialization is performed together (single line), we can omit the type declaration. Let's look at the following variable definition:
var title: String = "Kotlin"
The type of the title variable is String, but do we really need an implicit type declaration to determine variable type? On the right side of ...
Read now
Unlock full access