Appendix A
Features of Java and Kotlin
This appendix reviews many of the concepts and features discussed in the book, using an older language, Java, and a newer language, Kotlin, instead of Scala. Several examples written earlier in Scala are rewritten in Java or in Kotlin (or both). Code illustrations use Kotlin 1.7 and Java 19 (with some “preview” features enabled).
A.1 Functions in Java and Kotlin
Java and Kotlin both define methods—both are languages with an object-oriented leaning—and functions (see discussion in Section 9.4). Somewhat confusingly, Kotlin methods are called functions.
Methods and functions are introduced by the keyword fun
in Kotlin, whereas Java uses no keyword:
Java
int abs(int x) {
if (x > 0) return x;
else return ...
Get Functional and Concurrent Programming: Core Concepts and Features now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.