Hotwire Tech Blog

Scribes from Hotwire Engineering

What is Kotlin?

Kotlin is a new programming language from JetBrains, the maker of the world’s best IDEs.

  • Kotlin compiles to JVM bytecode or JavaScript.
  • Kotlin is a statically-typed programming language.
  • Kotlin is designed to interoperate with Java code and is reliant on Java code from the existing Java Class Library.
  • The syntax is lean and intuitive. It is a lot like Scala but much more comprehensible for Java developers. It does not completely destroy your OOP paradigm vision.
  • It does not enforce you to use only functional or only OOP style, which really simplifies the migration for existing Java project.
  • We can convert the existent Java classes to Kotlin from project with millions of lines of code and everything will still compile and work fine. The only thing needed is one additional dependency to your .pom file and everything will work just out of the box.

Some useful features:

  • Null-safety. It lets you avoid possible NullPointer Exceptions in compile time. Unlike some languages, this does not involve an option type and is therefore zero-overhead.
  • Lean syntax. Real properties generate getFoo/setFoo methods behind the scenes for Java interop.
  • Possible autogeneration of boilerplate like equals, hashCode, toString, just by adding proper annotation.
  • Functional programming support with zero-overhead lambdas and ability to do mapping, folding etc over standard Java collections.
  • String interpolation “works like ${this.helloWorld}!”
  • Internal DSL. Like many new modern languages Kotlin provide some advanced means for creating such things.

And many more cool features.


Hello World






Introducing  Kotlin to BDD

As the first step it was decided to add Kotlin dependency for mobile-api-step-defs module only, just to test its capabilities and to avoid any issues in common classes. We’ve started with transferring Java bean classes (e.g. we have Spring bean configuration in xml file and proper Java classes with fields, getters and setters for each bean’s property).

Next step was to transfer “Assertion classes” – classes that implement Assertion interface and have some custom assertion methods that are used across many other classes.

And the last: migration of the utility enums (e.g. types of test credit cards (Visa, MasterCard), types of the bookings (with credit card, with HotDollars) etc)



The above is how average migration in words of density looks like. The class with two fields has only 5 lines of code. Pretty cool even for such a small class.

Overall impression and plans for future

You can write code that’s more expressive and more concise than even a scripting language. It was pretty simple for me to start writing Kotlin code after reading its documentation. The “old good” Java, but much more succinct.

The plan for future is to fully migrate mobile-api-step-defs module to Kotlin. Usage of DSL will simplify and improve our test code even more.

Next step is to migrate some application code (together with proper test code) to Kotlin.

Already transferred code looks good now. We are full of optimism to move forward.


Leave a Reply

Your email address will not be published. Required fields are marked *