Kotlin vs. Java — Who's one step ahead?

Kotlin Team AMA highlights: Kotlin vs. Java, “under construction” features and more

Gabriela Motroc

© Shutterstock / ProStockStudio

The Kotlin Team AMA is over now but it’s been quite the ride. There were over 600 comments and the list of people from the Kotlin team grew bigger and bigger until there were 12 persons answering users’ questions. Let us know what your highlights are in the comments section.

The Kotlin team recently participated in a Reddit AMA and it seems that a lot of people chimed in — there are over 600 comments so we’re only going to talk about some of the highlights.

If you want to help, share your personal highlights in the comments section below.

Kotlin vs. Java: Who’s one step ahead?

One of the Redditors who participated in the AMA asked the Kotlin team if they are concerned that Java would eventually render Kotlin irrelevant since the former is stepping up their feature game (like auto type inference, or reified generics with project Valhalla). Kotlin lead language designer Andrey Breslav answered the following:

  • The JVM features we can and will pick up as they appear (this applies to Valhalla), so we are only happy when they appear.
  •  If the Java programming language becomes better than Kotlin in every respect, it will be really cool, because the world will benefit so much from it. Before it did, I think it’s still good that it’s making progress now. And competition tends to make you fit. So, I see it as a positive thing.

Also, if any language gets ahead of Kotlin, it means that it tries some features first, and it’s only to our benefit because we can learn from their experience and hopefully make the feature even better (this is what happened to coroutines, for example).

Bottomline: I’m not concerned with any positive progress any language in the world makes. I’m only happy with it :)

SEE ALSO: Can Kotlin overtake Java for Android development? New report says yes

Another Redditor pointed out that a lot has changed in the Java world and opined that the six-month cadence will bring a lot of changes. The Kotlin libraries team lead responded that even though he loves Java, some of its biggest problems are poorly chosen defaults, pervasive mutability, and nullability problems.

He added that it might be “nearly impossible” to transform Java into a “modern language while maintaining a reasonable degree of backward compatibility. There’ve been calls from Java community for backward-incompatible ‘Java 2.0’ many years ago. We finally have it. Kotlin is Java 2.0. The future of Java is Kotlin.”

Can Kotlin become too complex?

abishov asked the team if they are concerned that Kotlin could become too complex and bloated over time. Andrey Breslav explained that they “tend to focus on adding few features that change experience very significantly rather than many features with a smaller impact.”

Basically, they are doing their best to keep the language “lean and modern.” Also, he expressed the team’s desire to “make code shareable and it’s best possible when it’s written in one language.”

“Under construction” features

One Redditor asked what new features users should expect in future releases. According to Breslav, some of the features they are currently working on are:

  • Improving language support for multiplatform programming
  • Graduating coroutines
  • Writing common libraries for IO, sockets, serialization, dates, etc.
  • Bringing Kotlin/Native to release (currently it’s a Technology Preview): for iOS and other platforms
  • Setting up a central repository for Kotlin headers for JS libraries (aka “DefnitelyKotlin”)
  • Performance improvements in the compiler and IDE
  • Performance optimizations for generated code
  • Incremental compilation improvements in Kotlin/JVM and Kotlin/JS

SEE ALSO: Kotlin 1.2: Multiplatform projects across the JVM and JavaScript

Common mistakes that might impact performance: Tips & tricks

dgeorge92 asked the team to share some of their tips on how to avoid “common mistakes that might impact performance without being immediately obvious to the programmer.” Svetlana Isakova, Kotlin developer advocate and “Kotlin in Action” co-author explained that “it’s hard to reason about performance without specific examples and proper benchmarks” but offered the following tricks:

  • It’s important to understand the difference between inline operations on collections and lazy operations on sequences. If you say list.filter {}.map {} operations are inlined => an intermediate collection is created, which might be an unexpected performance drawback if the collection is big.
  • We don’t have primitive types in the language, it’s either Int or Int?. But Int is still primitive int in the bytecode (for most of the cases), while Int? is a wrapper type, so all the regular reasoning about primitive / wrapper types apply here.
  • Our lambdas are truly closures, meaning they can capture a mutable variable, but in this case, it works as you’d write it in Java: with creating additional Ref object storing the reference to the variable. And lambdas that capture no variables are cheaper because they are implemented using only one object at runtime.

Cool trick: “Show Kotlin bytecode” action, and then “decompile” button. Helps to understand what’s going on under the hood.

Check out the entire AMA here

Gabriela Motroc
Gabriela Motroc was editor of and JAX Magazine. Before working at Software & Support Media Group, she studied International Communication Management at the Hague University of Applied Sciences.

Inline Feedbacks
View all comments