Kotlin’s Improvements
Learn about how Kotlin has improved on some features of Java.
Let’s have a look at the four things we don’t need in Kotlin.
No semicolon necessary
In Kotlin, a semicolon (;
) to terminate a statement is not mandatory.
In contrast to Java and other languages, the Kotlin compiler usually recognizes the end of a statement even without an explicit ;
, for example, by a line break.
Note: The general rule in Kotlin is not to use semicolons.
However, two marginal exceptions should be noted.
Multiple expressions in the same line
If we want to note several statements in a single line, they are separated with ;
.
Press + to interact
fun main() {val a = 42 ; println(a)}
The semicolon after enum
constants
If we want to add properties or functions to an enum
class, we have to separate its constants with a ;
from the rest of the body: