AndroidPub
Published in

AndroidPub

Learn in 2 minutes: @JvmOverloads in Kotlin.

If you are coming from Java world, you might already have heard about the method overloading in Java. Kotlin, with the help of default parameters and named arguments helps us to reduce the number of overloads that we generally need in Java world.

That means, in Kotlin, you can define a method like

fun bar(a:Int=0, b: Double =0.0, c:String="default value"){
println("a=$a , b=$b ,c = $c")
}

And then call it like

bar(1)

--

--

The (retired) Pub(lication) for Android & Tech, focused on Development

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
Aanand Shekhar Roy

Aanand Shekhar Roy

Senior Software Engineer @Joist, Author of Kotlin Programming Cookbook.