No semicolon necessary
In Kotlin, a ;
terminating 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.
The general rule in Kotlin is not to use semicolons.
Two (marginal) exceptions should be noted:
Multiple expressions in the same line
If you want to note several statements in a single line, they are separated with ;
.
val a = 42 ; println(a)
Semicolon after enum
constants
If you want to add properties or functions to an enum class, you have to separate their constants with a ;
from the rest of the body:
enum class Weekdays {
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;
fun isWeekend() = this == SATURDAY || this == SUNDAY
}