Multiply Your name 10*ishan

ishan vimukthi
1 min readMar 26, 2020

Operator overloading in kotlin

Kotlin is a language with a beautiful syntax that runs on JVM. And compared to java the boilerplate code is so much less. In java we can concat a strings for an example if you write "ishan"+”ishan” gives you "ishanishan" but what happens when you want to multiply a string? 10*"ishan" nop it's not going to work in java but with kotlin you can do it so let's begin !

operator infix fun Int.times(word: String): String = word.repeat(this)println(10 * "ishan")

see elegant and simple now what happen you want to subtract a string i mean like this "ishan"-"an"="ish".

Yap you can do it too it goes like this

operator infix fun String.minus(word: String): String = word.replace(this, "")println("ishan" - "is")

--

--