3 ms·
In Kotlin, an infix method can be called without the `.` operator, and without the parens surrounding arguments. 100 money "USD" is the same as 100.m
by thomascgalvin 2y ago
In Kotlin, an infix method can be called without the `.` operator, and without the parens surrounding arguments.
100 money "USD"
is the same as
100.money("USD")
`Number.money(currency: String): Money` is an extension method; Kotlin provides syntactic sugar which allows you to "add" methods to existing classes. The above is basically equivalent to:
fun money(count: Number, currency: String): Money
- zellyn 2y agoThanks! I allowed myself to be distracted by all the weird infix stuff. I was thinking "but it's not passing itself into the money constructor" but it's actually just delegating to a different-signature version of `money` _on itself_ that will use its value then.
- adamgordonbell 2y agoGreat see that kotlin didn't avoid all Scala's bad ideas.