Skip to content

Instantly share code, notes, and snippets.

@harshgmp
Created August 31, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harshgmp/051181598b1042fa990b55e5b7c4f761 to your computer and use it in GitHub Desktop.
Save harshgmp/051181598b1042fa990b55e5b7c4f761 to your computer and use it in GitHub Desktop.
/**
* firstParam is of the type Integer which is called Int
* secondParam is of the type Int
* The last Int after colon and before the opening bracket of method is the return type, which is Int in our case
*/
fun multiply(firstParam : Int, secondParam : Int): Int {
return firstParam * secondParam
}
/**
* This function is same as above except that we do not have
* to explicitly declare the return type
*/
fun multiplyWithInferredReturnType(firstParam : Int, secondParam : Int) = firstParam * secondParam
/**
* This function is same as above except that we have explicitly mentioned return type as Unit
* which means none.
*/
fun multiplyWithUnitReturnType(firstParam : Int, secondParam : Int) : Unit {
println("${firstParam * secondParam}")
}
/**
* This function is same as above except that we have not explicitly mentioned return type as Unit
* which means none.
*/
fun multiplyWithNoReturnType(firstParam : Int, secondParam : Int) {
println("${firstParam * secondParam}")
}
fun main() {
println(multiply(10, 10))
println(multiplyWithInferredReturnType(13,10))
multiplyWithUnitReturnType(9,7)
multiplyWithNoReturnType(11,9)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment