Calling Java from Kotlin

This Atom is Under Construction

Calling Java libraries from Kotlin is intentionally very easy.

To use a Java library class from Kotlin, just import it as you would in Java, create an instance, and call a function:

// fromkotlin/Random.kt import atomictest.eq import java.util.* fun main(args: Array<String>) { val rand = Random(47) rand.nextInt(100) eq 58 }

As with creating any instance in Kotlin, you don’t need Java’s new. A class from a Java library works just like a native Kotlin class.

End of sample. See AtomicKotlin.com for full early-access book.



Previous          Next

©2018 Mindview LLC. All Rights Reserved.