← Back
Switching from Java to Kotlin: the most common mistake
Feb 23, 2023

In this article, we’ll discuss a common mistake beginners make when switching from Java to Kotlin for the first time. I often notice that people who have recently switched from Java to Kotlin become fascinated by its idiomaticity and start using it where they shouldn’t. 

For example:



What’s wrong here?

  • It’s unclear what the function returns.
  • It’s not obvious that the return value is nullable.
  • Without a hint, it’s unclear what the “let” applies to.
  • Large nesting depth.

There is also a logical error here, that has been made due to the difficulty of perceiving this construction — there is no check that “tags” is not empty.

You don’t need StringUtils either, Kotlin has isBlank() for strings.

How can you fix it?

  • Explicitly specify the return type.
  • Rewrite top-level logic in an imperative style


More information about us, as well as photos and videos in our public pages:
© Copyright 2024, FUNCORP

We plan to continue our growth and development by entering new markets and finding new business niches. Take a look at open positions. Perhaps there is one that is right for you!

If you know a passionate Software Developer who's looking for job opportunities, e-mail us at job@fun.co. In case of successful recommendation you will get a $3000 reference fee.