Calling Kotlin code in Java is similar to calling Java code in Kotlin, except for a few things that must be considered before beginning. Let's start with a function call. To do this, create a new folder and add both Java and Kotlin files in one place:
Calling Kotlin code in Java
Calling the Kotlin function
Now create two functions in Kotlin, add and addAndReturn. The add function takes two integer variables, adds them, and prints them on the screen, while addAndReturn adds two values and returns the result:
fun add(a : Int, b : Int) {
println("Result of $a + $b is ${a+b}")
}
fun addAndReturn(i: Int, j: Int): Int {
return i + j
}
We can call each Kotlin function by using the filename as a reference. CallKotlin...