Kotlin, the essence of Java

kotlin Mar 6, 2021

In this series of posts I want to show you how Kotlin improved on the Java language, without going into too much of the added features. Just the features that enhance your (existing) Java code.

It is intended for Java developers who want to make their code

  • More readable
  • Less redundant
  • Still Java-compatible

Therefor making you (and the people working with your code after you!) more productive.

My experience

I introduced Kotlin at the start of my last project and began by modeling our domain classes in Kotlin. Later on we grew more confident in the use of Kotlin and found ways to put it to use in more functional classes like services, builders and test helpers.

When I left the project team after 2.5 years members agreed with me that Kotlin greatly improved the code and that they would take this to other projects as well. I will too of course, using the posts in this series as proof/inspiration.

How to read

Introduce Kotlin to your team

This series is, I think, an easy introduction to Kotlin for the intermediate Java developer. Read the posts listed below, look at the examples and start using it at a scale you're comfortable with.

If you want to introduce Kotlin to your team or project, don't go overboard and go 100% Kotlin for your next project. Read these three posts and start using it right away!

This is enough to use Kotlin in your (existing) project!

Next steps

These posts tell you about more advanced features of Kotlin, but still within the 'boundaries' of this series.

  • Inline functions. It's a small topic, but I love it.
  • Streams. Like the Java streams but again just essential code. That is a more elaborate topic.

At that point I would suggest diving into the Kotlin language for real. Take a course, buy a book and of course follow my blog; I will post some examples how we used Kotlin for services, unit tests, builders in the future.

Alternative: Project Lombok

A lot of what you will see in the first post (Kotlin classes) can also be achieved by using Project Lombok. We've actually considered Lombok for our project and decided against it, because Lombok is mostly that: enhanced Java classes by annotation. From my experience, Kotlin is so much richer and let's you write beautiful code, not just annotate it.

No hard feelings if you decide to go with Lombok, but know that you'll be missing out on the inline functions and streams.

Tags