Infix Notation : Kotlin

This post was originally posted at https://agrawalsuneet.github.io/blogs/infix-notation-kotlin/ and reposted on Medium on 7th Oct 2018.
infix fun Int.add(b : Int) : Int = this + bval x = 10.add(20)
val y = 10 add 20 // infix call
  • They must be member functions or extension functions.
  • They must have a single parameter.
  • The parameter must not accept a variable number of arguments and must have no default value.

What if I use an infix function with other operators.

You can but you should keep the priority of the operator in mind.

Please continue reading at https://agrawalsuneet.github.io/blogs/infix-notation-kotlin/

It's completely free. No Account signup. No membership required. No Gimmick.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store