October 2018
Intermediate to advanced
370 pages
9h 15m
English
Kotlin is a language that is designed to maintain interoperability with Java code. The following example shows a nuance that we should take into account when we invoke Kotlin code from Java code. Let's create a simple Kotlin function that throws an exception:
fun testMethod() { throw IOException()}
This function can be called from Java code like this:
public class Example5 { public static void main(String[] args) { Example5Kt.testMethod(); }}
And this code can be compiled. This behavior can be unexpected for a Java developer who is used to dealing with checked exceptions. See what happens if we write something like this:
public static void testMethod() { throw new IOException();}
The compiler will show the following error: ...
Read now
Unlock full access