Calling Java code
Previously we saw what interoperability in code is like, we looked at it in a tangible way. We have a file that contains Kotlin code and another file that contains Java code, from the Kotlin file we call the class or any element that is defined in a Java file without problems.Now as an exercise and to clarify some points, we are going to share how this happens oppositely, that is, how a Java file uses the code of a Kotlin file.We are going to create a Java file as we normally do in Java by default:
Note
Remember that the Java code goes into the Java directory and the Kotlin code into the Kotlin directory.
Let’s start by creating a basic Java file:
public class Main {
public static void main(String[] args){
}
}
We are doing a literal translation of the Java code to Kotlin, but as we will see later this would be much better written in a different way in Kotlin, in fact it is much simpler and in fewer lines of code, we will see it later in this...