August 2018
Beginner
178 pages
4h 56m
English
This is another feature of Kotlin that is intended for creating DSLs. Infix functions are like normal functions, but they can be called without the dot and parentheses. To declare an infix function, you have to place the infix keyword before the fun keyword. Here's an example:
class Employee { infix fun payout(salary: Int) { print("Employee was paid: $salary") }}
Now, we can call the payout function without the dot and parentheses:
val employee = Employee()employee payout 3500
These conditions have to be satisfied to use the infix keyword:
Read now
Unlock full access