October 2018
Intermediate to advanced
370 pages
9h 15m
English
Open the CallJava file and add one static variable message:
public static String message = "Hello from Java";
As well as this, include one static method, add, which adds two variables and displays a message on the screen:
public static void add(int i, int j){ System.out.println(i + " + " + j + "=" + (i + j));}
Calling a static function or variable from Java to Kotlin is very simple. To do this, use the Java filename as a reference and call the required function or variable.
Look at the following Kotlin example to call the Java static variable:
fun callStaticFromJava() { var message = CallJava.message println("Java Message : ${message}") CallJava.add(4,5)}
To call the static variable, use the Java ...
Read now
Unlock full access