简体   繁体   中英

It is possible to have two functions with the same name in Kotlin

hey just new to kotlin from java and i want to ask if is possible to have two functions with the same name, for example i have a function name is " PrintVal " i want at least to make a three of this without to change the name how can doing this in kotlin

we can this way called overloading

Check this

Overloading refers to the ability to use a single identifier to define multiple methods of a class that differ in their input and output parameter make your functions but just change the parameter ( you should have a parameters)

Example:

   fun printVal(a : Int , b : Int){

        println(a+b)
    }

    fun printVal(a : Float , b: Float){

        println(a + b)
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM